Render method of ASP.net 2.0 server control

Source: Internet
Author: User
Tags html tags

Control rendering is the process of writing markup text to the HTTP output stream. The server sends the generated markup text to the client through the HTTP output, which is displayed through the conversion of the client browser to a visual element. With control rendering, developers can enter HTML tags, script code, CSS stylesheet, and so on to the client browser. There are two main ways to implement the server control rendering: One is the Render method and the other is the WebControl rendercontents method. This article focuses on the use of the control class render method to implement the application of controls rendering.

Using the HtmlTextWriter class

The Render method of the control class is primarily used to implement the rendering of controls, whose declaration code is as follows:

protected virtual void Render(HtmlTextWriter output)

As shown in the code above, the parameter of the Render method is a HtmlTextWriter type. In order to better apply the Render method, the reader should first understand the HtmlTextWriter class and its related content.

According to MSDN2005 's description, the HtmlTextWriter class is used to write markup characters and text to the ASP. NET server control output stream. This class provides the formatting features that ASP.net server controls use when rendering markup to clients. To implement the functionality of a class, the HtmlTextWriter class defines multiple fields, properties, and methods. Due to the large number of member objects, this article only selected some of the common members to explain, and will also introduce some ASP.net 2.0 new members.

Common member objects include:

· AddAttribute method

For the HtmlTextWriter object, add the specified tag properties and values to its opening tag by the element created by subsequent calls to the RenderBeginTag method.

· AddStyleAttribute method

For the HtmlTextWriter object, add the tag style attribute to its opening tag by the element created by subsequent calls to the RenderBeginTag method.

· Write method

Writes the specified data type along with any pending tab spacing to the output stream.

· WriteAttribute method

Writes a tag property and its value to the output stream.

· WriteBeginTag method

Any tab spacing and the start tag of the specified markup element are written to the output stream.

· Writeendtag method

Writes any tab spacing and closing tags for the specified markup element.

· Encoding Property

Gets the encoding that the HtmlTextWriter object uses to write content to the page.

· Indent Property

Gets or sets the number of tab positions that are used to indent the start position of each line of markup.

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.