- The first time the page is built/loaded everything works fine and the context menus are added.
- If I refresh the page once, the code that adds the context menus completes without error, however at some point just after Page_Load there is an unhandled exception "Script controls may not be registered after PreRender."
- If I try to refresh the page after that TreeView.ContextMenus.Add() throws an exception "The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases."
I have a project with a very stripped down example of the problem but it doesn't seem like theres a way for me to attach it here, so let me know if you'd like to see it. The full text of the two exceptions is below:
Exception 1Script controls may not be registered after PreRender.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.InvalidOperationException: Script controls may not be registered after PreRender.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
|
Exception 2
System.Web.HttpException was unhandled by user code
Message="The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases."
Source="System.Web"
ErrorCode=-2147467259
StackTrace:
at System.Web.UI.ControlCollection.RemoveAt(Int32 index)
at System.Web.UI.ControlCollection.Remove(Control value)
at System.Web.UI.Control.AddedControl(Control control, Int32 index)
at System.Web.UI.ControlCollection.Add(Control child)
at System.Web.UI.ControlCollection.AddAt(Int32 index, Control child)
at Telerik.Web.UI.RadTreeViewContextMenuCollection.OnInsertComplete(Int32 index, Object value)
at System.Web.UI.StateManagedCollection.InsertInternal(Int32 index, Object o)
at System.Web.UI.StateManagedCollection.System.Collections.IList.Add(Object value)
at Telerik.Web.UI.RadTreeViewContextMenuCollection.Add(RadTreeViewContextMenu target)
at _Default.AttachMenus() in e:\Source Control\<snip>\Default.aspx.cs:line 254
at _Default.Page_Load(Object sender, EventArgs e) in e:\Source Control\<snip>\Default.aspx.cs:line 81
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)