Rendering Engine of ASP. NET composite controls

Source: Internet
Author: User

Composite controls are suitable for building complex components. In composite controls, multiple child controls are aggregated and interacted with each other and with the outside. The Rendering Control is only used for read-only control aggregation. Its output does not include interactive elements such as drop-down boxes or text boxes ).

If you are interested in event processing and sending back data, I strongly recommend that you select a composite control. If a child control is used, it is easier to generate a complex control tree and the final result is clearer and more concise. In addition, the interface for sending back must be processed only when additional functions are required.

The rendering control not only requires the implementation of additional interfaces, but also the static part of the tag containing the property value.

The advantage of the composite control is that it can display multiple similar items, which is similar to the situation in the DataGrid Control. Enabling each component as an activity object enables you to trigger Creation events and programmatically access their properties. In ASP. NET 2.0, the above control is just an example for fully implementing the actual data binding.) Most of the sample code is hidden in the folding part of the new base class: CompositeDataBoundControl.

Rendering Engine of ASP. NET composite controls

Before in-depth discussion of ASP. NET 2.0 encoding technology, let's review the internal routine process of the composite control. As we mentioned, the composite controls are centrally rendered around the CreateChildControls method, which is inherited from the Control base class. You may think that replacing the Render method is an essential step for the server control to Render its content. As we can see before, if CreateChildControls is replaced, this step is not always required. But when will CreateChildControls be called in the control call stack?

As shown in, when the page is displayed for the first time, CreateChildControls is called in the pre-rendering phase.

ASP. NET Composite Control: CreateChildControls is called in the pre-rendering stage.

In particular, the request processing code is in the Page class. Before a PreRender event is triggered to the Page and each sub-control, EnsureChildControls is called directly. In other words, if the control tree is not completely generated, no control is displayed.

The following code snippet demonstrates the pseudo code of EnsureChildControls, which defines another method based on Control.

 
 
  1. protected virtual void EnsureChildControls()  
  2. {  
  3. if (!ChildControlsCreated)  
  4.    {  
  5. try {  
  6. CreateChildControls();  
  7.        }  
  8. finally {  
  9. ChildControlsCreated = true;  
  10.        }  
  11.    }  
  12. }  

This method may be called repeatedly during the lifecycle of pages and controls. To avoid repeated controls, the ChildControlsCreated attribute is set to true. If this property returns true, the method exits immediately.

When the page is sent back, ChildControlsCreated is called before the cycle. 4. It is called in the released data processing stage.

ASP. NET Composite Control: called in the released data processing stage when a message is sent back

When the ASP. NET page starts to process data published from the client, it will try to find a server control whose ID matches the name of the published field. During this step, the page code calls the FindControl method in the Control class. Otherwise, make sure that the control tree is fully generated before the operation. Therefore, it calls EnsureChildControls and generates the control hierarchy as needed.

So what is the code to be executed inside the CreateChildControls method? Although there is no formal guide to follow, it is generally considered that CreateChildControls must at least complete the following tasks: Clear the Controls set, generate the control tree, and clear the view status of the child control. It is not strictly required to set the ChildControlsCreated attribute from the CreateChildControls method. In fact, the ASP. NET page framework always uses EnsureChildControls to automatically set a Boolean flag) to call CreateChildControls.

  1. Overview of ASP. NET composite controls
  2. Analysis on Composite Control Event Processing Based on ASP. NET control development
  3. RenderContents application example of ASP. NET Server Control
  4. Analysis of ASP. NET custom control attributes
  5. Analysis of compound controls based on ASP. NET control development

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.