Startup script registered with ScriptManager.RegisterStartupScript is not rendered to page

点点圈 提交于 2019-12-13 17:19:31

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/4822355/startup-script-registered-with-scriptmanager-registerstartupscript-is-not-render

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!