Asp. NET rewrite render to load CSS style files and JS files (toggle css for skin)

Source: Internet
Author: User

There are many ways to skin a Web page, and the simplest is usually to switch between CSS and CSS, which is usually written in an external CSS file. Then switching CSS is actually replacing the link href path in HTML. I searched the internet for the next.

There are generally two ways:

1. Put a holder control on the page. Then programmatically write the current user's style CSS link to the page.

2. Over-reflection mechanism, set CSS style on a per-control basis.

The above two ways are very troublesome, the first need to put a holder control on each page, similar to the practice of adding link tag runat=server, page more, are more troublesome. The second is not considered, performance programming efficiency is a lot of problems.

Remember in the past when learning Dnn, in him found a change in the form of the default action address of the way, directly under the reference. Not bad:

Overriding the render event 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's a lot easier.

Of course, if you don't want to let each page inherit the custom base class, it can also be written in HttpModule. Also very convenient, a place to write well, page useful ah.

Asp. NET rewrite render to load CSS style files and JS files (toggle css for 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.