I have aspx page that use a Radgrid to display list of records,
During Editing command of the record, I am loading dynamically usercontrol "Record_Details.ascx" to display the record details using another Radgrid control "Record_Grid".
For that I am using OnNeedDataSource="RecoredRadGrid_OnNeedDataSource" event handler to load Record_Grid inside the usercontrol by passing the record ID from the RadGrid on the aspx page,
an error message is showing :"The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases"
Stack Trace:
[HttpException (0x80004005): The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.]
System.Web.UI.ControlCollection.Add(Control child) +11827274
Telerik.Web.UI.RadAjaxControl.CreateUpdatePanel(Control initiator, String eventName, Control updated, UpdatePanelRenderMode panelRenderMode, Unit panelHeight, String panelCssClass) +1935
Telerik.Web.UI.RadAjaxControl.OnPagePreRender(Object sender, EventArgs e) +3883
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnPreRender(EventArgs e) +11897165
System.Web.UI.Control.PreRenderRecursiveInternal() +107
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7675
I could find solution/workaorund to this issue by removing OnNeedDataSource of "Record_Grid" inside Record_Details.ascx , and load the datasource during ItemDataBound event handler of the Records RadGrid in .aspx page.
My question is why I am not able to use "OnNeedDataSource="RecoredRadGrid_OnNeedDataSource" to load the "Record_Grid" data from inside the Usercontrol, and error thrown each time I used it.