无为清净楼资源网 Design By www.qnjia.com
第一种:
直接把要嵌入的JS文件属性设置为“嵌入的资源”。
protected override void OnInit(EventArgs e)
{
      base.OnInit (e);
       if(!base.Page.IsStartupScriptRegistered("Script"))
        {
                Assembly assembly = typeof(TestControl).Assembly;
                StreamReader reader = null;
                 reader = new StreamReader(assembly.GetManifestResourceStream(typeof(TestControl),"test.js"));

                base.Page.RegisterStartupScript("Script",reader.ReadToEnd());

         }
}

第二种:
创建相同类名的资源文件,然后在Data出的name设置为Test,value为js的内容。

protected override void OnInit(EventArgs e)
{
      base.OnInit (e);
      if(!base.Page.IsStartupScriptRegistered("Script"))
       {
               ResourceManager resx = new ResourceManager(base.GetType());
               base.Page.RegisterStartupScript("Script",resx.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture,true,true).GetString("Test"));

        }
}
上面两种方式都是在控件类中输出JS代码,也可以自定义HttpHandler来生成Js代码。
标签:
控件开发时两种JS嵌入资源方式的使用方法

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com