Switch CSS to skin under Asp. Net

Source: Internet
Author: User

Switch CSS to skin under Asp. Net

There are many ways to change the skin, the simplest is usually to switch the page CSS, and CSS is usually written in an external CSS file. Switching css is actually replacing the link href path in html. I searched the internet. There are two methods:

1. Put a holder control on the page. Then, write the style css link of the current user into the page programmatically.
2. Use the reflection mechanism to set css styles one by one.
The above two methods are quite troublesome,
First, you need to put a holder control on each page. Similar practices include adding the link label with runat = server. Too many pages are troublesome.
The second option does not need to be considered. High Performance programming efficiency.

I remember that when I learned DNN, I found a way to modify the default action address in the form. For more information, see. Not bad:
Directly rewrite the Render event
Protected override void Render (System. Web. UI. HtmlTextWriter writer)
{
StringWriter sw = new StringWriter ();
HtmlTextWriter htmlWriter = new HtmlTextWriter (sw );

Base. Render (htmlWriter );
// The style css selected by the current user
String css = "<link href =/" css url/"rel =/" stylesheet/"type =/" text/css/"> ";

String html = sw. ToString ();
Int startPoint = html. IndexOf ("If (startPoint> 0)
{
Html = html. Insert (startPoint, css );
}

Writer. Write (html );
}
Put this in the base class PageBase of each page. It is much more convenient.
Of course, if you do not want to let every page inherit the custom base class, you can also write in HttpModule. It is also very convenient.
Write one page, and the page will be used.

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.