栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

把js文件编译成dll供页面调用的方法

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

把js文件编译成dll供页面调用的方法

1. 在解决方案中添加一个项目:JSControl

2. 在这个项目添加一个js文件(Jscript1.js)

脚本的内容:

function showalert(){
alert('Today is a good dary');
}

3. 改变Jscript1.js的属性,Build Action为Embedded Resource(嵌入的资源)

4. 在JSControl项目的AssemblyInfo.cs文件中添加一行:(注意JSControl.Jscript1.js,JSControl是命名空间,Jscript1.js是文件名)

[assembly: System.Web.UI.WebResource("JSControl.Jscript1.js", "application/x-javascript")]

5. 项目中增加一个注册客户端脚本的类:

namespace JSControl
{
public class Class1 : System.Web.UI.WebControls.WebControl
{
protected override void onPreRender(EventArgs e)
{
if (this.Page != null)
{
ClientscriptManager manager = this.Page.Clientscript;
manager.RegisterClientscriptResource(typeof(Class1), "JSControl.Jscript1.js");
}
base.onPreRender(e);
}
}
}

6. 在调用js的项目中添加JSControl.dll的引用

7. 要调用脚本的页面注册JSControl.dll

<%@ Register Assembly="JSControl" Namespace="JSControl" TagPrefix="zhi" %>







8. 调用

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/57063.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号