When creating a project, we need to dynamically change the style of all pages. However, when we set theme in the page command or web. config, there is a problem that I cannot pass Program To dynamically and consistently change the style of all pages, we recommend that you rewrite the onpreinit event and create a pagebase class in app_code, which inherits from system. web. UI. page, and then all the pages inherit from pagebase. You can see the specific implementation as follows:
Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
/// <Summary>
/// Summary of pagebase
/// </Summary>
Public class pagebase: system. Web. UI. Page
{
Public pagebase ()
{
//
// Todo: add the constructor logic here
//
}
Protected override void onpreinit (eventargs E)
{
Base. onpreinit (E );
If (request. Cookies ["skin"]! = NULL & request. querystring ["skin"] = NULL)
{
Page. theme = request. Cookies ["skin"]. value. tostring ();
}
Else
{
If (request. querystring ["skin"]! = NULL)
{
Httpcookie c = new httpcookie ("skin", request. querystring ["skin"]);
Response. Cookies. Add (C );
Page. theme = request. Cookies ["skin"]. value. tostring ();
}
Else
Page. theme = "skin ";
}
}
}