Defining a Custom Control Builder
The ASP.NET page framework uses classes called control builders to process the declarations
within control tags on a page. Every Web Forms control is associated with a default
control builder class, System.Web.UI.ControlBuilder. The default control builder
adds a child control to the Controls collection for every nested control that it
encounters within control tags. Additionally, it adds Literal controls for text
between nested control tags. You can override this default behavior by associating
a custom control builder class with your control. This is done by applying a control
builder attribute to your control, as shown in the following example.
Public Class <ControlBuilderAttribute(GetType(CustomParse2ControlBuilderVB))> _
CustomParse2VB : Inherits Control
VB
The element in square brackets above is a common language runtime attribute that
associates the CustomParse2ControlBuilder class with the
CustomParse2 control.
You can define your own custom control builder by deriving from ControlBuilder and
overriding its methods.
The following sample defines a custom control builder that overrides the
GetChildControlType method inherited from ControlBuilder. This method
returns the type of the control to be added and can be used to decide
which controls will be added. In the example, the control builder will
add a child control only if the tag name is "customitem". The code for
the control is very similar to the previous example, except for the addition
of the custom attribute.
Copyright 2001 Microsoft Corporation. All rights reserved.