Render, RenderChildren, and RenderControl

Source: Internet
Author: User

(1) protected virtual void Render (HtmlTextWriter writer );

This method is used to send the server control content to the provided HtmlTextWriter object, which is written into the content that will be presented on the client. When developing a server control, you can override this method to render the server control.

(2) protected virtual void RenderChildren (HtmlTextWriter writer );

This method is used to output the child-level content of the server control to the provided HtmlTextWriter object, which is written in the client. This method notifies ASP. NET of All Active Server Pages On the rendering page. If there is no ASP code on the page, this method will render all the child controls of the server control.

(3) protected virtual voidRenderControl(HtmlTextWriter writer); and protected voidRenderControl(HtmlTextWriter writer, ControlAdapter adapter)

  RenderControlThere are two overload methods that are used to output the content of the server control to the provided HtmlTextWriter object. If the tracking function is enabled, trace information about controls is stored. If the Visible attribute of the server control is set to true, this method determines whether the page tracking function is enabled. If enabled, it stores control-related trace information and presents the content of the server control to the page. In addition, the previous overload method is inherited by ASP. NET 2.0 from ASP. NET 1.0, and the last overload method is added by ASP. NET 2.0. The latter uses the provided ControlAdapter object to output the server control content to the provided HtmlTextWriter object. The adapter parameter is of the ControlAdapter type and is used to define the rendered ControlAdapter. This method is commonly used to implement server controls running on various devices and browsers.

The above three methods seem to be independent of the three methods. However, there is actually a close relationship between them. Readers can understand the relationship between them by reading the following schematic code.

// Basic implementation of the RenderCotrol Method
Public voidRenderControl(HtmlTextWriter output)
{
If (Visible)
{
Render (output );
}
}
// Basic implementation of the Render Method
Protected virtual void Render (HtmlTextWriter output)
{
RenderChildren (output );
}
// Basic implementation of the RenderChildren Method
Protected virtual void RenderChildren (HtmlTextWriter output)
{
Foreach (Control c in Controls)
{
C.RenderControl(Output );
}
}

As shown in the code aboveRenderControl, Render, RenderChildren method Implementation ideas. Obviously, these three methods play a role in the control rendering process, and a simple recursive call process is used. In general, it can be understood:

(1) Create an HtmlTextWriter class instance in the page framework;

(2) The page framework passes this instance objectRenderControlMethod;

(3)RenderControlMethod to check whether the Visible property Visible of the control is true. If it is true,RenderControlThe Render method is called. If it is false, the Control and Its subcontrols are not displayed;

(4) The Render method is implemented by default and the RenderChildren method is called;

(5) The RenderChildren method callsRenderControlMethod;

In fact, it does not matter if you cannot understand the above process in a short time. For beginners, the key is to remember the most important and commonly used Render method. The control developer can override the Render method to complete the rendering control task.

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.