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.