当前位置: 编程技术>.net/c#/asp.net
asp.net 组件开发 内嵌资源引用的例子
来源: 互联网 发布时间:2014-08-30
本文导语: 例子代码如下: 代码示例: [assembly: System.Web.UI.WebResource("XXX.js.FilePlugin.js", "text/javascript")] OnPreRender事件 //资源名称 string _strResourceKey = ""; //资源名称 ClientScriptManager _csm = Page.ClientScript; //if (this.Page.Header.FindControl(_strResourceKe...
例子代码如下:
代码示例:
[assembly: System.Web.UI.WebResource("XXX.js.FilePlugin.js", "text/javascript")]
OnPreRender事件
//资源名称
string _strResourceKey = ""; //资源名称
ClientScriptManager _csm = Page.ClientScript;
//if (this.Page.Header.FindControl(_strResourceKey) == null)
//{
// string _src = _csm.GetWebResourceUrl(this.GetType(), _strResourceKey);
// Literal _literal = new Literal();
// _literal.ID = _strResourceKey;
// _literal.Text = string.Format("n", _src);
// this.Parent.Page.Header.Controls.Add(_literal);
//}
//if (!this.Page.ClientScript.IsStartupScriptRegistered(_strResourceKey))
//{
// string _src = _csm.GetWebResourceUrl(this.GetType(), _strResourceKey);
// _src = string.Format("n", _src);
// Page.ClientScript.RegisterStartupScript(this.GetType(), _strResourceKey, _src);
//}
if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(_strResourceKey))
{
string _src = _csm.GetWebResourceUrl(this.GetType(), _strResourceKey);
Page.ClientScript.RegisterClientScriptInclude(this.GetType(), _strResourceKey, _src);
}
OnPreRender事件
//资源名称
string _strResourceKey = ""; //资源名称
ClientScriptManager _csm = Page.ClientScript;
//if (this.Page.Header.FindControl(_strResourceKey) == null)
//{
// string _src = _csm.GetWebResourceUrl(this.GetType(), _strResourceKey);
// Literal _literal = new Literal();
// _literal.ID = _strResourceKey;
// _literal.Text = string.Format("n", _src);
// this.Parent.Page.Header.Controls.Add(_literal);
//}
//if (!this.Page.ClientScript.IsStartupScriptRegistered(_strResourceKey))
//{
// string _src = _csm.GetWebResourceUrl(this.GetType(), _strResourceKey);
// _src = string.Format("n", _src);
// Page.ClientScript.RegisterStartupScript(this.GetType(), _strResourceKey, _src);
//}
if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(_strResourceKey))
{
string _src = _csm.GetWebResourceUrl(this.GetType(), _strResourceKey);
Page.ClientScript.RegisterClientScriptInclude(this.GetType(), _strResourceKey, _src);
}