无法注册启动脚本

Ana*_*nth 1 .net javascript c# jquery

我在btn Click事件中使用以下代码:

 ClientScript.RegisterStartupScript(typeof(Page), "exampleScript", "alert('you just registered the start up script');", true);
Run Code Online (Sandbox Code Playgroud)

脚本在里面注册<body>,我没有得到任何警报.

注册启动脚本并获取此警报消息的方法是什么?

Mas*_*uso 5

你在使用AJAX吗?

因此,只要在页面上有ScriptManager实例,就需要使用ScriptManager注册脚本.所以你需要改变这样的代码

ScriptManager.RegisterStartupScript(this, this.GetType(), "exampleScript", "alert('Hello');", true);
Run Code Online (Sandbox Code Playgroud)