前几天在给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![](/Images/OutliningIndicators/None.gif)
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);
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
14
![](/Images/OutliningIndicators/None.gif)
15
![](/Images/OutliningIndicators/None.gif)
16
![](/Images/OutliningIndicators/None.gif)
17
![](/Images/OutliningIndicators/None.gif)
18
![](/Images/OutliningIndicators/None.gif)