在PreRender之后,可能无法注册扩展程序控件。在GridView DataBind()上发生

时间:2011-03-22 20:07:40

标签: c# asp.net data-binding prerender extender

在我们的ASP.Net 4.0 C#网络应用程序中,我在调试期间在主题行中收到上述错误。

由于某些搜索结果显示可能是问题的根源,我在页面上使用动态控件时并没有做任何时髦的事情。

该页面有2个ajax:CalendarExtenders,并且已经运行了一段时间。

虽然它可能是相关的,但我可以看到它是多么真实,但这是我在错误出现时正在进行的工作。

我们在页面上有一个控件,可以在自动刷新功能上引发事件。 [它是地图控制]。

我的页面订阅了该事件,并在这样做时绑定了asp:GridView。我们需要每次都绑定网格中的数据,以确保网格和地图控件同步。 [它是车辆追踪页面]

DataBind命令发生错误。

我删除了Extenders只是为了提出同样的错误。

数据绑定很简单,但我确定错误存在于其他地方。无论如何我都会把它包括在内。

this.SearchGrid.DataSource = resultsWithMetrics;

        this.SearchGrid.AllowPaging = true;
        this.SearchGrid.PageIndex = this.SearchGridPager.CurrentPage;
        this.SearchGrid.AllowPaging = this.SearchGridPager.PageSize > 0;
        this.SearchGrid.PageSize = this.SearchGridPager.PageSize > 0 ? this.SearchGridPager.PageSize : this.SearchGrid.PageSize;

        this.SearchGrid.DataBind();

也许它根本不理解让我绊倒的页面生命周期,无论如何都会很高兴得到一些帮助。

2 个答案:

答案 0 :(得分:1)

在用户控件或页面控件中使用以下代码。如果您使用的是ajax控件,它将起作用。

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        if (this.DesignMode == true)
        {
            this.EnsureChildControls();
        }
        this.Page.RegisterRequiresControlState(this);
    } 

答案 1 :(得分:0)

问题是在行数据绑定中,扩展程序控件被添加到每一行,而这些扩展程序导致了这个问题。

触发重新绑定的事件来自用户控件,该控件使用回调与服务器进行通信,并随后引发可能在页面生命周期中无法到达的事件。

如果没有完全理解发生了什么,所有人都会闻到一点点狡猾,我已经改变了应用程序的结构。

相关问题