RenderControl (asp.net)

Source: Internet
Author: User

When you want to output the html code of a control including the content (for example, exporting word or excel or directly outputting it, or returning it through httpxmlrequest), you must use the control's
Rendcontrol () method, such as gridview:
System. IO. StringWriter oStringWriter = new System. IO. StringWriter ();
System. Web. UI. HtmlTextWriter oHtmlTextWriter = new System. Web. UI. HtmlTextWriter (oStringWriter );
MyGrid. RenderControl (oHtmlTextWriter );
Response. Write (oStringWriter. ToString ());
Response. End ();


The page will create an HtmlTextWriter class instance. The corresponding stream is encapsulated in this instance, and the page will pass the HtmlTextWriter object to RenderControl. RenderControl will check whether the Visible attribute of the control is true, if it is true, RenderControl will call the Render method, while the Render method will call RenderContents. The RenderContents method is responsible for displaying the control content to the specified writer. If the control has a child control, the Render method passes HtmlTextWriter to the RenderChildren method. The RenderChildren method is used to generate child controls of the control.

We can think that the rendercontrol method first outputs the control content to htmlTextWriter, And because ostringwriter is associated with htmltextwriter, the content is stored in ostringwriter and then through response. write (ostringwriter. tostring () output.


 

Author Zheng wenliang

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.