to change the skin by switching CSS

Source: Internet
Author: User

There are many ways to change skin, the simplest is usually to switch page CSS, and CSS is usually written in the external CSS file. Then switch CSS is actually the replacement HTML link href path. I searched the internet for the next. There are generally two ways:

1, put a holder control on the page. The current user's style CSS link is then written to the page programmatically.
2, through the reflection mechanism, the CSS style is set individually.
Both of these ways are troublesome,
The first one needs to put a holder control on each page. A similar approach is to add runat=server to the link tag. More pages, more trouble.
The second is out of the consideration. There are a lot of problems with performance programming efficiency.

Remember before learning Dnn, in him found a way to modify the default action address in the form, direct reference. Not bad:
overriding render events directly
protected override void Render (System.Web.UI.HtmlTextWriter writer)
StringWriter SW = new StringWriter ();
HtmlTextWriter htmlwriter = new HtmlTextWriter (SW);

Base. Render (HTMLWriter);
Current user-selected style CSS
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. That would be a lot more convenient.
Of course, if you don't want to inherit the custom base class for each page, you can also write it in HttpModule. is also very convenient.
One place is written, the page is good.

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: 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.