62,046
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 最后一次HTML改动之前注册js,css
/// </summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
AddCss("Control.css.jquery.dd.css");
AddJs("Control.js.jquery.js", "Control.js.jquery.dd.js");
if (this.Page != null)
{
if (!this.Page.ClientScript.IsStartupScriptRegistered(string.Format("{0}_ExtendDropDownInited", this.ClientID)))
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), string.Format("{0}_ExtendDropDownInited", this.ClientID), string.Format("<script>MSDropDown.init('#{0}');</script>", this.ClientID));
}
}
}
/// <summary>
/// 向页面添加css引用
/// </summary>
/// <param name="cssNames"></param>
private void AddCss(params string[] cssNames)
{
if (cssNames is string[])
{
if (this.Page == null || this.Page.Header == null)
{
return;
}
foreach (string cssName in cssNames)
{
if (!this.Page.ClientScript.IsStartupScriptRegistered(string.Format("_bpms_{0}_", cssName)))
{
HtmlLink css = new HtmlLink();
css.Attributes.Add("type", "text/css");
css.Attributes.Add("rel", "stylesheet");
css.Attributes.Add("src", this.Page.ClientScript.GetWebResourceUrl(this.GetType(), cssName));
if (this.Page.Header != null)
{
this.Page.Header.Controls.Add(css);
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), string.Format("_bpms_{0}_", cssName), "");
}
}
}
}
}
/// <summary>
/// 向页面添加js引用
/// </summary>
/// <param name="jsNames"></param>
private void AddJs(params string[] jsNames)
{
if (jsNames is string[])
{
if (this.Page == null || this.Page.Header == null)
{
return;
}
foreach (string jsName in jsNames)
{
if (!this.Page.ClientScript.IsStartupScriptRegistered(string.Format("_bpms_{0}_", jsName)))
{
HtmlGenericControl script = new HtmlGenericControl("script");
script.Attributes.Add("type", "text/css");
script.Attributes.Add("rel", "stylesheet");
script.Attributes.Add("src", this.Page.ClientScript.GetWebResourceUrl(this.GetType(), jsName));
if (this.Page.Header != null)
{
this.Page.Header.Controls.Add(script);
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), string.Format("_bpms_{0}_", jsName), "");
}
}
}
}
}
HtmlGenericControl script = new HtmlGenericControl("script");
script.Attributes.Add("type", "text/css");
script.Attributes.Add("rel", "stylesheet");
script.Attributes.Add("src", this.Page.ClientScript.GetWebResourceUrl(this.GetType(), jsName));