我在btn
Click
事件中使用以下代码:
ClientScript.RegisterStartupScript(typeof(Page), "exampleScript", "alert('you just registered the start up script');", true);
该脚本已在
<body>
中注册,但没有收到任何警报。注册启动脚本并获取此警告消息的方式是什么?
最佳答案
您正在使用AJAX吗?
因此,只要页面上有ScriptManager实例,就需要使用ScriptManager注册Script。所以你需要像这样更改代码
ScriptManager.RegisterStartupScript(this, this.GetType(), "exampleScript", "alert('Hello');", true);
关于c# - 无法注册启动脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9197770/