ScriptManager.RegisterStartupScript

如果页面中不用Ajax,cs中运行某段js代码方式可以是:
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>window.open('default2.aspx')</script>");
如果页面中使用了Ajax ,则上述代码即使执行也无效果。对这种情况我们通常采用:
ScriptManager.RegisterStartupScript(this.Button1, this.GetType(), "alertScript", "window.open('default2.aspx');", true);
其中第一个参数为要注册脚本的控件ID,试了一下,只要是本页面的就行。
第二个参数为注册脚本控件类型,是控件还是this的GetType()都可以,typeOf(string)也没问题.
第三个脚本函数的名字,随便起。
第四个是脚本内容。
第五个是标明是否再添加脚本标签,如果第四个参数里包含了<script></script>标签,此处则为false,否则为true。

原文地址:https://www.cnblogs.com/sunzgod/p/4205197.html