ASP.NET提供了三种后台输出JS的方式
2011-08-02 11:09
393 查看
ASP.NET提供了三种后台输出JS的方式:
一、后台输出已有js文件
首先创建 js文件testjs.js
二、输出js代码块
三、 输出一次性使用的js代码
此外,运用Response.Write(" "); 方式也可输出简单js代码,但我个人不提倡采用此种方式。因为在以前开发中遇到有些情况下此种方式会导致弹出提示信息后页面字号改变的现象,所以安全起见建议采用上述三种方式。
一、后台输出已有js文件
首先创建 js文件testjs.js
以下是代码片段: if (!Page.ClientScript.IsClientScriptIncludeRegistered(this.GetType(), "keys"))//判断keys是否已注册过 { Page.ClientScript.RegisterClientScriptInclude("keys", "testjs.js"); } |
以下是代码片段: string scriptstrs = "";//此处只作为演示,如代码需多次拼接应采用StringBuilder方式 scriptstrs += "function test(str)"; scriptstrs+="{alert(str);}"; if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "keys")) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "keys", scriptstrs, true); } |
以下是代码片段: string scriptstrs = ""; if (!Page.ClientScript.IsStartupScriptRegistered(this.GetType(),"welcome")) { Page.ClientScript.RegisterStartupScript(this.GetType(), "welcome", scriptstrs); } |
相关文章推荐
- 【转】ASP.NET后台输出js的三种方式
- ASP.NET后台输出js的三种方式(写给初学者)
- ASP.NET后台调用前台JS函数的三种常见方法
- net 后台输出js asp.net 后台输出js 方法
- ASP.NET后台输出js脚本代码
- ASP.NET后台调用前台JS函数的三种常见方法
- ASP.NET后台输出js大全,页面顶部、form表单中前面与后面、和UpdatePanel(ScriptManager、AJAX)输出JS
- ASP.NET后台输出js
- asp.net 后台输出js方法
- asp.net后台cs中的JSON格式变量在前台Js中调用方法!(前后台实例!)
- 【转载】Asp.net中后台*.cs与前台JS脚本之间相互调用心得
- 声明的方式控制ASP.NET输出缓存策略
- ASP.NET学习笔记七之CSS加载的三种方式
- ASP.Net 关于前台JS给input赋值后,runat="server" 后台利用ID.Value还是获取不到的问题
- asp.net中后台c#数组与前台js数组交互
- ASP.NET自定义输出缓存提供程序
- asp.net调用前台js调用后台代码分享
- asp.net后台加脚本的几种方式
- ASP.NET中后台注册js脚本攻略(转)