C # Implementing methods for compressing HTML code

Source: Internet
Author: User

This article describes the C # implementation of the method of compressing HTML code, shared for everyone for reference. Here's how:

The main code is as follows:

<summary>///compressed HTML code///</summary>///<param name= "writer" ></param>protected override void Render (HtmlTextWriter writer) {  System.IO.StringWriter html = new System.IO.StringWriter ();  HtmlTextWriter TW = new HtmlTextWriter (HTML);  Base. Render (TW);  String outhtml = html. ToString ();  outhtml = System.Text.RegularExpressions.Regex.Replace (outhtml, "\\n+\\s+", String. Empty);  outhtml = outhtml. Trim ();  Writer. Write (outhtml);}

Disable unnecessary viewstate: This everyone knows, the page does not understand the long string of characters is viewstate, which will probably occupy 15%~40% around the amount of HTML code, reduce ViewState imperative, if the current page does not use any ViewState, And you don't want a control to close it with a control, you can use the following code

protected override void Render (HtmlTextWriter writer) {  System.IO.StringWriter html = new System.IO.StringWriter ();  HtmlTextWriter tw = new HtmlTextWriter (HTML);  Base. Render (TW);  String outhtml = html. ToString ();  outhtml = System.Text.RegularExpressions.Regex.Replace (outhtml, "<input\\stype=\" hidden\ "\\sname=\" __viewstate \ "\\sid=\" __viewstate\ "value=\" .+\\/> ", String. Empty);  outhtml = outhtml. Trim ();  Writer. Write (outhtml);}

I hope this article is helpful to everyone's C # program design

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
C # Implementing methods for compressing HTML code

This address: http://www.paobuke.com/develop/c-develop/pbk23566.html






Related content C # using the Nopi Library implementation to import Excel documents C # 4 ways to create an irregular form in the C # implementation of TXT positioning specify a row full instance C # setting page units and Scaling methods
Tail recursion in C # and continuation detailed C # implementation of file breakpoints download Method C # The Youku real-world Video Address resolution feature (2014 New algorithm) a summary of several practical tips in WinForm

C # Implementing methods for compressing HTML code

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.