首页 > Web开发 > 详细

控件开发时两种JS嵌入资源方式的使用方法

时间:2015-11-28 07:45:15      阅读:236      评论:0      收藏:0      [点我收藏+]
第一种:
直接把要嵌入的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嵌入资源方式的使用方法

原文:http://www.jb51.net/article/9732.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!