I have an asp.net usercontrol that represents the "popup" dialog. Basically, this is a wrapper for the jQuery user interface dialog box, which can be subclassed to easily create dialogs.
As part of this control, I need to enter a div on the page on which the control is used, either at the very top or at the bottom of the form, so that when the popup is instantiated, the parent element will be changed to this div. This allows nested pop-ups if the popup of the child does not fall into the parent popup.
The problem is that I cannot find a safe way to insert this div into the page. Usercontrol does not have a preinit event, so I cannot do this, and calling Page.Form.Controls.Add (...) on Init, Load or PreRender raises a standard exception. "The control collection cannot be changed during DataBind, Init, Load, PreRender or Unload events."
I thought I found a solution using ...
ScriptManager.RegisterClientScriptBlock(Page, Me.GetType, UniqueID + "_Dialog_Div", containerDiv, False)
... which seemed to work fine, but recently a colleague tried to put the UpdatePanel in the dialog box and now she gets the error "Script tag registered for type" ASP.controls_order_viewzips_ascx "and the key" ctl00 $ ContentBody "$ OViewZips_Dialog_Div 'has invalid characters outside script tags: only correctly formatted script tags can be registered. "
How should you add controls to the page control collection from a user control?
source share