向ScriptManager.RegisterStartupScript注册的启动脚本未呈现到页面 [英] Startup script registered with ScriptManager.RegisterStartupScript is not rendered to page

查看:70
本文介绍了向ScriptManager.RegisterStartupScript注册的启动脚本未呈现到页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET 3.5中有一个对ScriptManager.RegisterStartupScript的调用,该调用没有呈现到页面上,我不知道为什么:

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 );

上面的调用位于基类(ListControlBase)中的按钮处理程序内,该基类由用户控件和UpdatePanel(列表管理器控件)子类化.此用户控件的存在是为了管理其他用户控件(列表项控件)的1到n个副本的列表,这些副本在UpdatePanel的PlaceHolder中动态添加,更新或删除.为了进行测试,我尝试添加1个和2个List Item Control副本.

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.

使用LoadControl(采用ascx路径的重载)实例化List Manager控件,并将其添加到代表我正在创建的完整表单的控件中的PlaceHolder中.至此,所有控件都存在于Web应用程序项目中.然后,将完整窗体控件添加到父网站项目中存在的页面对象中的PlaceHolder中,再次使用LoadControl(与上述相同的重载)进行实例化.

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.

如果我取出UpdatePanel,则对RegisterStartupScript的调用将导致按预期方式呈现启动scxript.

If I take out the UpdatePanel the call to RegisterStartupScript results in the startup scxript being rendered as expected.

将UpdatePanel保留在其中,我已使用调试器来确保在Web应用程序项目中调用RegisterStartupScript之后以及在主项目页面的OnPreRender方法中立即向ScriptManager注册脚本.

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:

进入QuickWatch:(((System.Web.UI.ScriptManager)(Page.ScriptManager))._ scriptRegistration._startupScriptBlocks

Entered into QuickWatch: ((System.Web.UI.ScriptManager)(Page.ScriptManager))._scriptRegistration._startupScriptBlocks

正如我所说,从Web应用程序项目和Web站点项目进行调试时,都可以在QuickWatch中看到已注册的启动脚本,但是它不会呈现到页面中,这是我使用Firebug检查过的.

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.

我搜索了互联网,包括StackOverflow,但没有成功.有人有什么想法吗?是否可以在监视窗口中检查一些ScriptManager属性,以使我对此有所帮助?

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?

感谢任何想法...

推荐答案

正如Will所建议的,这很可能是IIS开发中的问题.重新启动计算机后,它消失了.

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

这篇关于向ScriptManager.RegisterStartupScript注册的启动脚本未呈现到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆