On our ASP.Net 4.0 C# web app I get the error above in the subject line during debug.

I'm not really doing anything funky with dynamic controls on the page as some search results indicated could have been the source of the problem.

The page has 2 ajax:CalendarExtenders and has been working fine for a while.

Although its probably related, I can see how really but this is what I was currently working on when the error came up.

We have a control on the page that raises an event on an autorefresh feature. [Its a map control].

My page subscribes to that event and upon doing so DataBinds an asp:GridView. We need to bind the data in the grid every time to ensure the grid and the map control are in sync. [Its a vehicle tracking page]

The error occurs on the DataBind command.

I have removed the Extenders only to come up with the same error.

The databind is straightforward but I'm sure the error resides elsewhere. I'll include it anyway.

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();

Maybe its simply not understanding the page life cycle that has tripped me up, anyway would be glad of some help.

有帮助吗?

解决方案

Use the following code in your usercontrol or page control. It will work if you are using any ajax control.

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

其他提示

The issue was that on row databind the extender controls were added to each row and it was these extenders that caused the issue.

The event that triggered the the rebind came from a user control that used callbacks to communicate to the server and subsequently raise the event which probably arrived too late anyway in the page lifecycle.

Without fully understanding what was going on it all smelt a bit dodgy and I have changed the structure of the app a bit.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top