asp.net运行时动态修改主题
生活随笔
收集整理的這篇文章主要介紹了
asp.net运行时动态修改主题
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
對(duì)自己已知的實(shí)現(xiàn)asp.net動(dòng)態(tài)修改主題的方式做一個(gè)小總結(jié)
方式一:
在頁(yè)面的PreInit事件中直接設(shè)置。該方法可實(shí)現(xiàn)不同頁(yè)面加載不同主題,如果要實(shí)現(xiàn)網(wǎng)站整體換膚,只需要?jiǎng)?chuàng)建一個(gè)從System.Web.UI.Page類派生的子類,在該類的PreInit事件中加載特定主題,最后所有頁(yè)面繼承自此類即可。
代碼:
protected override void OnPreInit(EventArgs e)
{
??? this.Theme="MyTheme";
??? base.OnPreInit(e);
}
其中“MyTheme”為主題名,可從外部文件或數(shù)據(jù)庫(kù)加載,以實(shí)現(xiàn)主題設(shè)置的持久化。
==================================================================================
方式二:
在global.asax中捕獲HttpApplication的PreRequestHanderExecute事件
在事件中為Page的PreInit事件添加處理程序
global.asax中的代碼如下
void Application_PreRequestHandlerExecute(object src,EventArgs e)
{
??? Page page=this.Context.Handler as Page;
??? if(page!=null)
??? {
??? ?? page.PreInit+=new EventHandler(page_PreInit);
??? }
}
void Page_PreInit(object sender,EventArgs e)
{
??? Page page=this.Context.Handler as Page;
??? if(page!=null)
??? {
??? ?? page.Theme="MyTheme";
??? }
}
================================================
方法三:
運(yùn)行時(shí)修改配置文件
protected void btnTheme_Click(object sender, EventArgs e)
{
??? Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~");
??? ((PagesSection)(webConfig.GetSectionGroup("system.web").Sections["pages"])).Theme = “MyTheme”;
??? webConfig.Save(ConfigurationSaveMode.Modified);
}
==============================2008-6-25========================================
方式一:
在頁(yè)面的PreInit事件中直接設(shè)置。該方法可實(shí)現(xiàn)不同頁(yè)面加載不同主題,如果要實(shí)現(xiàn)網(wǎng)站整體換膚,只需要?jiǎng)?chuàng)建一個(gè)從System.Web.UI.Page類派生的子類,在該類的PreInit事件中加載特定主題,最后所有頁(yè)面繼承自此類即可。
代碼:
protected override void OnPreInit(EventArgs e)
{
??? this.Theme="MyTheme";
??? base.OnPreInit(e);
}
其中“MyTheme”為主題名,可從外部文件或數(shù)據(jù)庫(kù)加載,以實(shí)現(xiàn)主題設(shè)置的持久化。
==================================================================================
方式二:
在global.asax中捕獲HttpApplication的PreRequestHanderExecute事件
在事件中為Page的PreInit事件添加處理程序
global.asax中的代碼如下
void Application_PreRequestHandlerExecute(object src,EventArgs e)
{
??? Page page=this.Context.Handler as Page;
??? if(page!=null)
??? {
??? ?? page.PreInit+=new EventHandler(page_PreInit);
??? }
}
void Page_PreInit(object sender,EventArgs e)
{
??? Page page=this.Context.Handler as Page;
??? if(page!=null)
??? {
??? ?? page.Theme="MyTheme";
??? }
}
================================================
方法三:
運(yùn)行時(shí)修改配置文件
protected void btnTheme_Click(object sender, EventArgs e)
{
??? Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~");
??? ((PagesSection)(webConfig.GetSectionGroup("system.web").Sections["pages"])).Theme = “MyTheme”;
??? webConfig.Save(ConfigurationSaveMode.Modified);
}
==============================2008-6-25========================================
轉(zhuǎn)載于:https://www.cnblogs.com/whs475/archive/2008/06/25/1229433.html
總結(jié)
以上是生活随笔為你收集整理的asp.net运行时动态修改主题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Visual C# 诠释常用排序算法
- 下一篇: asp.net ajax控件工具集 Au