Developing Custom Controls - Part 1
page 5 of 8
by G. Mohyuddin
Feedback
Average Rating: 
Views (Total / Last 10 Days): 35672/ 107

Custom Server Controls

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.


View Entire Article

User Comments

Title: Comparing UC vs CC is awesome   
Name: satya
Date: 2010-03-22 11:16:17 PM
Comment:
Differences b/w User controls, Custom controls are explained excellently.
Title: Error Rendering Control   
Name: Luiz Ricardo
Date: 2009-03-27 9:17:41 AM
Comment:
I have "Error rendering control" when I change TextCaseMode or any other enum property at design time.
Did I forget anything?
Title: Good   
Name: Raju
Date: 2009-03-23 6:29:02 AM
Comment:
At design time,if I change the property it will show
error rendering control
Title: Looks promising   
Name: JP
Date: 2008-12-10 5:56:38 AM
Comment:
reusable in true sense!
Title: Testing   
Name: Tester
Date: 2008-12-10 5:40:56 AM
Comment:
Really good
Title: Good show !   
Name: Ananth
Date: 2008-06-09 3:56:36 PM
Comment:
Nice and Neat !!
Title: Really Intresting   
Name: Uzair Aziz
Date: 2008-03-14 8:58:48 AM
Comment:
It is really helpful and easy to understand for me.now i can develop other custom controls.

Tnank you so much.....
Title: thanks   
Name: ngocthom
Date: 2008-01-09 10:58:04 PM
Comment:
thanks so much for your supply, it is very useful






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-18 12:26:27 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search