ClientScript.RegisterStartupScript用来向前台页面注册script脚本,有两种重载方法,分别为ClientScript.RegisterStartupScript(Type type,string key ,string script);ClientScript.RegisterStartupScript(Type type,string key, string script,bool flag);
其中ClientScript.RegisterStartupScript(Type type,string key,string script)这个方法中,script要加上“<script></script>”.
而);ClientScript.RegisterStartupScript(Type type,string key, string script,bool flag);可以直接写成ClientScript.RegisterStartupScript(Type.GetType(),"",jsScript名称,true);这样在前台注册的时候可以自动加上<script></script>,
其中还有一个比较重要的一项是key,如果key设置的相同的话,就会第一个覆盖下面的jsScript代码,而失去效应,所以在用的时候要把key设置不同。
如这样
string javaScript = @" <script language = javascript> alert('测试1'); </script> ";
ClientScript.RegisterStartupScript(this.GetType(), "javaScript", javaScript);
string javaScript2 = @" <script language = javascript> alert('测试2'); </script> ";
ClientScript.RegisterStartupScript(this.GetType(), "javaScript2", javaScript2);
分享到:
相关推荐
最近在用ASP .NET的code behind 调用javascript中发现Response.Write不能拿到form的值,而ClientScript.RegisterStartupScript可以。
如果不用Ajax,cs中运行某段js代码方式可以是: Page.ClientScript.RegisterStartupScript(Page.GetType(), “”, “[removed]window.open(‘default2.aspx’)[removed]”); 如果页面中使用了Ajax ,则上述代码即使...
if (this.txtDLM.Text.Trim() == "") { Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('登录名不能为空!');</script>"); return; } if (this.txtMM.Text.Trim() != this....
// Page.ClientScript.RegisterStartupScript(Page.GetType(),"alert1", "alert('test')",true); //在生成页面的后半部分!! //Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),"alert1", ...
avascript与c#后台交互 1.在后台c#代码中调用jacascript的方法 javascript代码: function test() ... ClientScript.RegisterStartupScript(this.GetType(), "clear", "<script>test()</script>"); }
1.ClientScript.RegisterStartupScript(GetType(),”message”,”[removed]alert(‘第一种方式,无白屏!’);[removed]”); 2.HttpContext.Current.Response.Write(“[removed]alert(‘第二种方式,有白屏...
page.ClientScript.RegisterStartupScript(typeof(string), "message", "$(document).ready(function() { var para = { mode: 'sample',message:'"+msg+"', title: '提示信息', firstboxval: $(\"#fileText\")....
一般弹窗 代码如下: Page.ClientScript.RegisterStartupScript(this.GetType(), “message”, “alert(‘确定删除吗’)”, true); 第一个参数不会变, 第二个参数是键值的意思,如果只有一个弹出对话框的...
Pub_Function.Message_Box.Show(this.Page... this.ClientScript.RegisterStartupScript(this.GetType(), "", "[removed]alert('Save Success!');[removed]='../ShipManage/InvChkTime_Set.aspx';[removed]");
接下来为大家介绍下使用Page.ClientScript.RegisterClientScriptBlock 和Page.ClientScript.RegisterStartupScript:区别
用page.ClientScript.RegisterStartupScript方式实现 代码为: 代码如下: /**//// <summary> /// 弹出JavaScript小窗口 /// </summary> /// ”js”>窗口信息</param> public static void Alert(string message, ...
if (FileUpload1.HasFile == false) { Page.ClientScript.RegisterStartupScript(this.GetType(), “shifou”, “[removed]alert(‘请您选择 Excel文件’)[removed] “); return; }
代码如下: this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, “window.opener.location.reload();alert(‘销帐成功!’);”, true); 主要是这段js代码:window.opener.location.reload...
Father 1.新建一个按钮 代码如下: ”btnFresh” runat=”server” Text=”” xss=removed> 2.JS 代码如下: [removed] ... } [removed] Son 1.cs 代码如下: ClientScript.RegisterStartupScript(Page.GetType(), “”,
4.4.1 使用Page.ClientScript. RegisterClient ScriptBlock100 4.4.2 使用Page.ClientScript. 18.2.2 基于Windows的 身份验证模式615 18.2.3 基于窗体的身份验证622 18.2.4 Passport身份验证631 18.3 ...