IE8 说“无法显示网页”使用动态占位符时

发布于 2024-09-15 02:32:32 字数 1523 浏览 0 评论 0原文

我有一个使用占位符的 ASP.NET 页面。网格以编程方式构建,并在页面运行时添加到此占位符中。示例:

ASPX 代码:

<asp:PlaceHolder ID="myPlaceHolder" runat="server" />

代码隐藏:

foreach (var country in Tables.Countries())
{
  var nGrid = BuildGrid(country.Code);
  if (nGrid.Rows.Count > 0)
  {
      var lTitle = new Literal();
      lTitle.Text = "<h2>Stats for country " + country.Name + "</h2>";

      myPlaceHolder.Controls.Add(lTitle);
      myPlaceHolder.Controls.Add(nGrid);
  }
  nGrid.Dispose();
}

private GridView BuildGrid(short countryCode)
{
    GridView nGrid = new GridView();
    nGrid.ID = "gr_" + countryCode;
    nGrid.SkinID = "rpSkin";
    nGrid.AutoGenerateColumns = false;
    nGrid.AllowPaging = false;
    nGrid.AllowSorting = false;
    nGrid.RowStyle.VerticalAlign = VerticalAlign.Top;
    nGrid.EnableViewState = false;

    var nField = new BoundField
                                 {
                                     HeaderText = "People",
                                     DataField = "PeopleCount"
                                 };
                nGrid.Columns.Add(nField);

    // more BoundFields of this type exist

    // This is basically the GridViewHelper class that gets Row Totals
    // Disabling this doesn't help, either
    HelpGrid(nGrid);
    nGrid.DataSource = Country.GetPeople(countryCode);
    nGrid.DataBind();
    return nGrid;
}

该页面在 Opera 和 Firefox 中完美运行。 Internet Explorer 8 显示“无法显示网页”屏幕。

有什么想法吗?

I have a ASP.NET page using a PlaceHolder. Grids are build programmatically and added to this PlaceHolder when the page is run. Example:

ASPX Code:

<asp:PlaceHolder ID="myPlaceHolder" runat="server" />

Code behind:

foreach (var country in Tables.Countries())
{
  var nGrid = BuildGrid(country.Code);
  if (nGrid.Rows.Count > 0)
  {
      var lTitle = new Literal();
      lTitle.Text = "<h2>Stats for country " + country.Name + "</h2>";

      myPlaceHolder.Controls.Add(lTitle);
      myPlaceHolder.Controls.Add(nGrid);
  }
  nGrid.Dispose();
}

private GridView BuildGrid(short countryCode)
{
    GridView nGrid = new GridView();
    nGrid.ID = "gr_" + countryCode;
    nGrid.SkinID = "rpSkin";
    nGrid.AutoGenerateColumns = false;
    nGrid.AllowPaging = false;
    nGrid.AllowSorting = false;
    nGrid.RowStyle.VerticalAlign = VerticalAlign.Top;
    nGrid.EnableViewState = false;

    var nField = new BoundField
                                 {
                                     HeaderText = "People",
                                     DataField = "PeopleCount"
                                 };
                nGrid.Columns.Add(nField);

    // more BoundFields of this type exist

    // This is basically the GridViewHelper class that gets Row Totals
    // Disabling this doesn't help, either
    HelpGrid(nGrid);
    nGrid.DataSource = Country.GetPeople(countryCode);
    nGrid.DataBind();
    return nGrid;
}

This page works flawlessly in Opera and Firefox. Internet Explorer 8 shows me the "cannot display the webpage" screen.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青丝拂面 2024-09-22 02:32:32

以编程方式创建控件时,您总是会遇到大量问题。它可能适用于 get,但不适用于 post,您在 OnClick 处理程序等中遇到问题。为了使编程控件正常工作,您必须跳过很多环节。

在我看来,您确实不需要以编程方式创建这些。您可以像创建用户控件一样轻松地创建网格控件,然后传递您的数据源。如果需要,您可以在运行时加载用户控件,然后删除整个构建网格的动态部分,让 ASP.NET 来处理这些混乱的事情。

这并不是说你不能做到这一点,就像人们一直在做的那样。我只是建议你要为自己做更多的工作才能按照自己的方式去做。

You're always going to run into a ton of problems when programmatically creating controls. It may work on get, but not on post, you have issues in OnClick handlers, etc.. there's a lot of hoops you have to jump through to make programmatic controls work right.

It really doesn't look to me like you absolutely need to programmatically create these. You could just as easily create the grid control as a user control, then pass your DataSource through. If need be, you can load the user controls at runtime, and you cut out the whole build the grid dynamiclaly part and let asp.net take care of the mess.

This is not to say you can't do it, as people do all the time. I'm just suggesting that you're setting yourself up for a lot more work to do it the way you are.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文