ScriptManager.RegisterStartupScript code不工作 - 为什么? [英] ScriptManager.RegisterStartupScript code not working - why?
本文介绍了ScriptManager.RegisterStartupScript code不工作 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用code这样在过去的成功弹出一个警告消息,在我的asp.net网页。现在,它是行不通的。我想不通为什么。
I have used code like this in the past to successfully pop up an alert message on my asp.net webpage. Now it is not working. I can't figure out why.
ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID,
"alert('This pops up')", true);
任何想法?
推荐答案
关闭我的头顶:
- 使用
的GetType()
而不是typeof运算(页)
以脚本绑定到你的实际页面类而不是基类, - 传递一个键常量而不是
Page.UniqueID
,这是不是有意义名为控制,因为它应该被使用, - 以分号结束你的JavaScript语句,
- 在
preRender
阶段注册脚本:
- Use
GetType()
instead oftypeof(Page)
in order to bind the script to your actual page class instead of the base class, - Pass a key constant instead of
Page.UniqueID
, which is not that meaningful since it's supposed to be used by named controls, - End your Javascript statement with a semicolon,
- Register the script during the
PreRender
phase:
protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "YourUniqueScriptKey",
"alert('This pops up');", true);
}
这篇关于ScriptManager.RegisterStartupScript code不工作 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文