Now getting specific to custom controls they are Pre
Compiled in nature. As mentioned earlier, there three types of custom control
with respect of their requirement and way of developing them. Types of custom
controls are Extended, Composite and Fully Custom. It is important to note that
these categories are not hard and fast. There can be a control that can fall
into all three categories simultaneously. It can be a totally new, composite
and may have its constituent controls extended, composite or new ones. We will
explore them separately. Let us take a look on each of these types with respect
to their requirement and development method.
Extended
If there is a standard web server control that meets most of
our requirements and you want it to do few more tasks, then you will go for
extended custom control. You will add a few more properties to achieve the
desired tasks. For this purpose you extend the existing web server control,
letting the new one inherit the full functionality set and behavior of the
existing control and adding the required ones.
Composite
You build a new control combining functionality of two or
more existing controls. Suppose you want to build a control named PrimeTester;
you would be required to include three standard web server controls to make it
accomplished. It will combine functionality of a Textbox, Button and Label. A
TextBox for input, a Button to test if it is prime and a Label to show the test
result. Many standard web server controls shipped with ASP.NET are of composite
nature. A simpler example is ASP.NET CheckBox control. Its gets rendered into
two html controls. Say there is the following ASP.NET Checkbox control on the
page.
Listing 1
<asp:CheckBox id=”checkbox1” runat=”server”
Text=”This is simple composite control” … />
If you see the source of the page in the browser, you will
notice that it has been rendered into these controls.
Listing 2
<input type=”checkbox” id=checkbox1…/> and
<Label for=” checkbox1”> This is simple composite control </Label >
Since the html control “input” of type checkbox cannot support storing and displaying the contents of Text property of the ASP.NET Checkbox control,
the html Label control has been added to keep record of the text of the
Checkbox. The “for” property of the html label control keeps the ID of the
associated Checkbox.
We will see composite custom controls in detail with a
working example of a new composite control in Part II of the article.
Fully Custom
When none of the standard web server controls fulfills your
requirements, what you want is entirely different from the functionality of any
existing server control. You need to go for an entirely new one that neither
extends any of the standard web server controls nor combines functionality of
an exiting control. Based on the functionality of a fully custom control, it
might have to implement one or more of the interfaces System.Web.UI.INamingContainer,
System.Web.UI.IPostBackDataHandler
or System.Web.UI.IPostBackEventHandler.
We will look on fully custom controls in detail with a working example of a new
fully custom control in Part II of the article.