ASP.net instance code protected override void Render (HtmlTextWriter writer) _ Basic application

Source: Internet
Author: User
protected override void Render (HtmlTextWriter writer)
{
The final output of the HTML to compress and then output
StringWriter html = new StringWriter ();
HtmlTextWriter TW = new HtmlTextWriter (HTML);
Base. Render (TW);
String outhtml = html. ToString ();
outhtml = Regex.Replace (outhtml, "\\s+", "");
outhtml = Regex.Replace (outhtml, ">\\s+<", "><");
outhtml = outhtml. Trim ();
Writer. Write (outhtml);
}

protected override void Render (HtmlTextWriter writer)
{
The final output is first saved as an HTML file, and if you publish the latest information, you can open a default.aspx, and then he will generate an HTML

This is the default render implementation, directly output to the writer
Base. Render (writer);
StringWriter html = new StringWriter ();
HtmlTextWriter TW = new HtmlTextWriter (HTML);
Through base. Render () method that writes the generated HTML to our defined TW
Base. Render (TW);
String path = Server.MapPath ("index.html");
StreamWriter sw = new StreamWriter (path, false, System.Text.Encoding.Default);
Write to File
Sw. Write (HTML. ToString ());
Sw. Close ();
Writes to the writer to output the HTML of the page
Note that base can no longer be called here. Render (writer), there will be an error
Writer. Write (HTML. ToString ());
}
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: 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.