给web控件加入资源文件

前几天在给web控件加资源文件的时候晕死我了,怎么也加不进去,后来看了一篇文章恍然大悟,流程如下
1.把资源文件加入到项目下
2.点文件,属性,生成操作改成嵌入的资源
3.在AssemblyInfo.cs 里加入引用如
[assembly: System.Web.UI.WebResource("Controls.image.icon_page_end.gif", "image/gif")]
这里Controls是项目的命名空间,image是目录,后面是文件名,第二个参数是文件类型
4.用到资源的地方写成这样
imgbtnPre.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "Controls.image.icon_page_end.gif");

另外像JS文件应该在PreRender事件中注入

 1 //  注册所需脚本
 2              if  ( ! this .Page.ClientScript.IsClientScriptIncludeRegistered( this .GetType(),  " Tip " ))
 3              {
 4                this.Page.ClientScript.RegisterClientScriptInclude
 5                (
 6                    this.GetType(),
 7                    "Tip",
 8                    this.Page.ClientScript.GetWebResourceUrl
 9                    (this.GetType(), "Controls.Js.Check.js")
10                );
11            }

12
13              //  注册所需样式
14             System.Web.UI.HtmlControls.HtmlLink link  =   new  System.Web.UI.HtmlControls.HtmlLink();
15             link.Attributes[ " type " =   " text/css " ;
16             link.Attributes[ " rel " =   " stylesheet " ;
17             link.Attributes[ " href " =  Page.ClientScript.GetWebResourceUrl( this .GetType(),  " Controls.CSS.Controls.css " );
18              this .Page.Header.Controls.Add(link);

转载于:https://www.cnblogs.com/song0320/articles/1040722.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值