Custom styles implemented by ASP. net2.0

Source: Internet
Author: User
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 ";
}
}
}

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.