js文件编译成动态链接库(dll)文件

1.向项目中添加Jscript文件

1//script1.js-----
2function doClick1()
3{
4    alert("OK");
5}



2.解决方案资源管理器中,右键查看script_1.js的属性,把高级中的“生成操作”属性设置成“嵌入的资源”。


3.向AssemblyInfo.cs文件中添加如下行注意名称: 名称= 程序集名 + 目录名 +  文件名, yj.WebControl.ClientScriptResourceTest.script1.js 为名称)
[assembly: System.Web.UI.WebResource("yj.WebControl.ClientScriptResourceTest.script1.js", "application/x-javascript")]

4.向项目中添加一个类, 实例:

 1using System;
 2using System.Drawing;
 3using System.Web.UI;
 4using System.Web;
 5using System.Globalization;
 6namespace yj.WebControl
 7{
 8    public class ClientScriptResourceTest : Control
 9    {
10        //调用脚本资源
11        protected override void OnLoad(EventArgs e)
12        {
13            if (this.Page != null)
14            {
15                this.Page.ClientScript.RegisterClientScriptResource(typeof(ClientScriptResourceTest), 
16                    "yj.WebControl.ClientScriptResourceTest.script1.js");
17            }

18
19            base.OnLoad(e);
20        }
 
21    }

22}

23


 

原文地址:https://www.cnblogs.com/yejiansnake/p/1269953.html