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