I have a call to ScriptManager.RegisterStartupScript in ASP.NET 3.5 that isn't being rendered to the page and I can't figure out why:
System.Web.UI.ScriptManager.RegisterStartupScript( Page
, typeof(ListControlBase)
, "ShowPopup_" + ClientID
, "alert(\"HI\");"
, true );
The above call sits inside of a button handler in a base class (ListControlBase) that is sub-classed by a user control with an UpdatePanel (List Manager Control). This user control exists to manage a list of 1 to n copies of another user control (List Item Control) that are dynamically added, updated, or deleted within a PlaceHolder in the UpdatePanel. For testing I've tried adding both 1 and 2 copies of the List Item Control.
The List Manager Control is instantiated using LoadControl (the overload that takes the ascx path) and added to a PlaceHolder in a control representing the full form that I am creating. Up to this point all controls exist in the web application project. The full form control is then added to a PlaceHolder in the page object, which exists in the parent web site project, again using LoadControl (same overload as above) for instantiation.
If I take out the UpdatePanel the call to RegisterStartupScript results in the startup scxript being rendered as expected.
Leaving the UpdatePanel in, I have used the debugger to ensure that the script is indeed registered with the ScriptManager, both immediately after the call to RegisterStartupScript in the web application project and in the OnPreRender method of the page in the main project:
Entered into QuickWatch: ((System.Web.UI.ScriptManager)(Page.ScriptManager))._scriptRegistration._startupScriptBlocks
As I said, I can see the registered start-up script in QuickWatch when debugging from both the web application project and the web site project, however it does not get rendered to the page, which I have checked using Firebug.
I have searched the internet, including StackOverflow multiple times with no success. Does anyone have any ideas? Is there some ScriptManager property that I can check in the watch window that might give me a lead on this?
Thanks for any ideas...
As Will suggests, this is likely a development IIS issue. After restarting the machine it went away.