Make a small summary of your own known ways to implement ASP.net dynamically modified themes
Mode one:
Set directly in the PreInit event of the page. This method can achieve different pages load different themes, if you want to achieve the overall site skin, only need to create a subclass from the System.Web.UI.Page class, in the class PreInit event loaded a specific topic, finally all pages inherit from this class.
Code:
protected override void Onpreinit (EventArgs e) {this. Theme= "MyTheme"; Base. Onpreinit (e); }
where "MyTheme" is the primary title, can be loaded from an external file or database to achieve the persistence of the theme settings.
==================================================================================
Mode two:
Capturing HttpApplication Prerequesthanderexecute events in Global.asax
Add a handler for the PreInit event of the page in the event
The code in Global.asax is as follows
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"; } }
================================================
Method Three:
Modify configuration file at run time
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========================================