asp.net dynamically modify themes at run time

Source: Internet
Author: User

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========================================

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.