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 1An 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. |
|
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)
Protected Sub gridActivities_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles gridActivities.ItemDataBound
If (TypeOf e.Item Is GridEditFormInsertItem) AndAlso (gridActivities.MasterTableView.IsItemInserted) Then
Dim insertItem As GridEditFormInsertItem = CType(e.Item, GridEditFormInsertItem)
'getting the Textbox in the insert form using it's UniqueName
Dim txbCategoryID As TextBox = CType(insertItem("intCategory").Controls(0), TextBox)
txbCategoryID.Text = Request.QueryString("Category")
End If
End Sub
What am I doing wrong?