1

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...

5
  • stackoverflow.com/questions/802506/… Commented Jan 27, 2011 at 21:59
  • 1
    This was a snipe hunt. Logged out and back into OS and the problem went away. Something must've gotten jammed up in memory. Commented Jan 28, 2011 at 2:53
  • please answer your own question and, after a couple days, you can select it as correct. It sounds weird, but that's the way we do it around here, because it won't void the work Tim put into trying to help. Also, what you said leads me to believe that the development IIS server was the issue, which is supported by the fact you're debugging in firefox. What can happen is that you'll build run, test, and then shut down firefox... but the IIS server will still be running. Just go down in the system tray and manually shut down IIS server if it happens again. Its a FF issue. Commented Jan 28, 2011 at 18:00
  • @Will - will do. Thanks for SOP info. BTW, how does debugging in Firefox factor into this? Commented Feb 1, 2011 at 2:03
  • VS, I think, can't figure out that FF has closed and so doesn't know to shut down the dev server. Or something. Commented Feb 1, 2011 at 14:43

2 Answers 2

2

Have a look at the overloaded version of RegisterStartupScript that takes an Control: MSDN: ScriptManager.RegisterStartupScript Method (Control, Type, String, String, Boolean)

Registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page.

Sign up to request clarification or add additional context in comments.

1 Comment

I did try this with no luck. Thanks.
2

As Will suggests, this is likely a development IIS issue. After restarting the machine it went away.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.