欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

控件開發(fā)時兩種JS嵌入資源方式的使用方法

 更新時間:2007年04月28日 00:00:00   作者:  
第一種:
直接把要嵌入的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());

         }
}

第二種:
創(chuàng)建相同類名的資源文件,然后在Data出的name設置為Test,value為js的內(nèi)容。

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代碼。

相關文章

最新評論