网站首页 > 网页设计教程 > Javascript教程 > 将js文件编译成动态链接库(dll)文件

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

  • 作者:互联网
  • 时间:2009-06-09 20:24:23

1.向项目中添加Jscript文件
//***ipt_1.js-----
function doClick1()
{
    alert("OK1_wufeng");
}
//***ipt_2.js-----
function doClick2()
{
    alert("OK2");
}

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

3.向As***blyInfo.cs文件中添加如下行:(注意域名wf***ientScriptResourceLabel)
[assembly: Sy***m.Web.UI.WebResource("wf***ientScriptResourceLabel.sc***t_1.js", "application/x-javascript")]
[assembly: Sy***m.Web.UI.WebResource("wf***ientScriptResourceLabel.sc***t_2.js", "application/x-javascript")]

4.向项目中添加一个类, 实例:
using System;
using Sy***m.Drawing;
using Sy***m.Web.UI;
using Sy***m.Web;
using Sy***m.Globalization;

namespace wf***ientScriptResourceLabel
{
    public class ClientScriptResourceLabel : Sy***m.Web.UI.WebControls.WebControl
    {
        //调用脚本资源
        protected override void OnPreRender(EventArgs e)
        {
            if (th***Page != null)
            {
                th***Page.ClientScript.RegisterClientScriptResource(typeof(ClientScriptResourceLabel), "wf***ientScriptResourceLabel.sc***t_1.js");
                th***Page.ClientScript.RegisterClientScriptResource(typeof(ClientScriptResourceLabel), "wf***ientScriptResourceLabel.sc***t_2.js");
            }
            ba***OnPreRender(e);
        }


        ///


        /// 呈现控件的方法RenderContents
        ///

        protected override void RenderContents(HtmlTextWriter output)
        {
            ou***t.AddAttribute("id", "1");
            ou***t.AddAttribute("type", "checkbox");
            ou***t.AddAttribute("value", "测试1");
            ou***t.AddAttribute("onclick", "javascript:doClick1();");
            ou***t.RenderBeginTag(Ht***extWriterTag.Input);
            ou***t.RenderEndTag();

            ou***t.AddAttribute("id", "2");
            ou***t.AddAttribute("type", "checkbox");
            ou***t.AddAttribute("value", "测试2");
            ou***t.AddAttribute("onclick", "javascript:doClick2();");
            ou***t.RenderBeginTag(Ht***extWriterTag.Input);
            ou***t.RenderEndTag();

            ba***RenderContents(output);
        }
    }
}


大家可以试试