ClientScript.RegisterStartupScript

简介: ClientScript.RegisterStartupScript用来向前台页面注册script脚本。 //此处是从页面接受变量,然后弹出 string mm =Request["name"];string yhm=Request["pswd"];ClientScript.RegisterStartupScript(this.GetType(), "message", "&

ClientScript.RegisterStartupScript用来向前台页面注册script脚本。

//此处是从页面接受变量,然后弹出

string mm =Request["name"];
string yhm=Request["pswd"];
ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript'>alert('Name="+mm + ",PassWord="+ yhm+"');</script>");

小注:

C#传入变量时记住要"+变量名+"这么成对的传入。alert()的括号中需要有一对单引号,引起其中的变量。

//下面这句,可以实现弹出对话框后,单击确定同时关闭页面

ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' >alert('输入用户名或密码错误!');window.opener=null;window.top.open('','_self','');window.top.close(this);</script>");
例子:

string a = "aaaa";
string b = "bbbb";
string c = "cccc";
ClientScript.RegisterStartupScript(this.GetType(), "IsPostBack1", " <script> alert('IASID=" + a + ",Result=" + b + ",UserAccount=" + c + "' ); </script> ");

初始状态:

ClientScript.RegisterStartupScript(this.GetType(), "IsPostBack1", " <script> alert(''); </script> ");

第一步写上,需要原样输出的内容:

ClientScript.RegisterStartupScript(this.GetType(), "IsPostBack1", " <script> alert('IASID=',Result=,UserAccount='); </script> ");

第二步写上,变量:

ClientScript.RegisterStartupScript(this.GetType(), "IsPostBack1", " <script> alert('IASID=" + a +",Result=," + b +"UserAccount=" + c +"'); </script>");

ok完成!

  相同颜色的逗号彼此配对。
目录
相关文章
|
5月前
|
小程序 API
点餐小程序实战教程09-订单功能开发
点餐小程序实战教程09-订单功能开发
|
XML 前端开发 Android开发
Android XML 布局基础(四)内外边距(margin、padding)
Android XML 布局基础(四)内外边距(margin、padding)
251 0
|
12月前
|
缓存
POST 为什么会发送两次请求?
POST 为什么会发送两次请求?
799 0
|
5月前
|
移动开发 小程序
微信小程序配置服务器域名和业务域名
微信小程序配置服务器域名和业务域名
517 0
|
Windows
成功解决http error 503.the service is unavailable错误
成功解决http error 503.the service is unavailable错误
2436 0
|
XML 前端开发 IDE
在 Compose 中使用 Jetpack 组件库
Jeptack Compose 主要目的是提高 UI 层的开发效率,但一个完整项目还少不了逻辑层、数据层的配合。幸好 Jetpack 中不少组件库已经与 Compose 进行了适配。
904 0
|
存储 Linux 数据安全/隐私保护
什么是 Linux 中的机器 ID?
什么是 Linux 中的机器 ID?
921 0
|
SQL 移动开发 Java
企业内部应用接入钉钉获取部门及人员信息
企业内部应用接入钉钉,同时通过API获取当前企业下部门及人员信息
企业内部应用接入钉钉获取部门及人员信息
|
自然语言处理 算法 搜索推荐
|
小程序 JavaScript
微信小程序请求封装(http请求详解)
微信小程序请求封装(http请求详解)