ASP. NET composite controls and CompositeControl

Source: Internet
Author: User

CompositeControl for Solving Design Issues

With ASP. NET 2.0, a base class named CompositeControl is provided. Therefore, the new non-data-bound composite control should be derived from this class rather than from WebControl. The usage of CompositeControl has not changed much in terms of development controls. You still need to replace CreateChildControls and encode it as described earlier. So what is the role of CompositeControl? Let's start with its prototype:

 
 
  1. public class CompositeControl :WebControl,   
  2. INamingContainer,   
  3. ICompositeControlDesignerAccessor  

When using this class, you do not need to use INamingContainer to decorate the control, but it is not very important because the interface is just a tag and does not contain any methods. More importantly, this class implements a new interface named ICompositeControlDesignerAccessor.

 
 
  1. public interface ICompositeControlDesignerAccessor  
  2. {  
  3. void RecreateChildControls();  
  4. }  

This interface is used by the standard designer of the Composite Control to recreate the control tree during design. The following is the default implementation process of the methods in CompositeControl.

 
 
  1. void ICompositeControlDesignerAccessor.RecreateChildControls()  
  2. {  
  3. base.ChildControlsCreated = false;  
  4. EnsureChildControls();  
  5. }  

In short, if you derive a CompositeControl from CompositeControl, you will not encounter design failures, and you will be able to run the control properly at runtime and design without the need for tips and tricks.

To fully understand the importance of this interface, you can take the example page of a LabelTextBox composite control as an example and convert it to the design mode. The control works normally during operation, but is invisible during design.

Figure 5: Only CompositeControl controls are derived from CompositeControl for special design-time processing.

If you only use CompositeControl to replace WebControl, the control continues to work normally during runtime, and will also run well during design.

Figure 6: Composite controls that work well at design

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

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.