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