将js文件编译成动态链接库(dll)文件
1.向項(xiàng)目中添加Jscript文件
//script_1.js-----
function doClick1()
{
alert("OK1_wufeng");
}
//script_2.js-----
function doClick2()
{
alert("OK2");
}
2.解決方案資源管理器中,右鍵查看script_1.js和script_2.js的屬性,把高級(jí)中的“生成操作”屬性設(shè)置成“嵌入的資源”。
3.向AssemblyInfo.cs文件中添加如下行:(注意域名wf.ClientScriptResourceLabel)
[assembly: System.Web.UI.WebResource("wf.ClientScriptResourceLabel.script_1.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("wf.ClientScriptResourceLabel.script_2.js", "application/x-javascript")]
4.向項(xiàng)目中添加一個(gè)類, 實(shí)例:
using System;
using System.Drawing;
using System.Web.UI;
using System.Web;
using System.Globalization;
namespace wf.ClientScriptResourceLabel
{
public class ClientScriptResourceLabel : System.Web.UI.WebControls.WebControl
{
//調(diào)用腳本資源
protected override void OnPreRender(EventArgs e)
{
if (this.Page != null)
{
this.Page.ClientScript.RegisterClientScriptResource(typeof(ClientScriptResourceLabel), "wf.ClientScriptResourceLabel.script_1.js");
this.Page.ClientScript.RegisterClientScriptResource(typeof(ClientScriptResourceLabel), "wf.ClientScriptResourceLabel.script_2.js");
}
base.OnPreRender(e);
}
/// <summary>
/// 呈現(xiàn)控件的方法RenderContents
/// </summary>
protected override void RenderContents(HtmlTextWriter output)
{
output.AddAttribute("id", "1");
output.AddAttribute("type", "checkbox");
output.AddAttribute("value", "測(cè)試1");
output.AddAttribute("onclick", "javascript:doClick1();");
output.RenderBeginTag(HtmlTextWriterTag.Input);
output.RenderEndTag();
output.AddAttribute("id", "2");
output.AddAttribute("type", "checkbox");
output.AddAttribute("value", "測(cè)試2");
output.AddAttribute("onclick", "javascript:doClick2();");
output.RenderBeginTag(HtmlTextWriterTag.Input);
output.RenderEndTag();
base.RenderContents(output);
}
}
}
大家可以試試
轉(zhuǎn)載于:https://www.cnblogs.com/top5/archive/2010/06/13/1757684.html
總結(jié)
以上是生活随笔為你收集整理的将js文件编译成动态链接库(dll)文件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 耍了一下 UncaughtErrorEv
- 下一篇: 上周热点回顾(6.14-6.20)