Reusing and Creating Server Controls
page 1 of 4
Published: 08 Jan 2004
Unedited - Community Contributed
Creating our very own server controls is very easy... but when several controls share similar behavior and functionality, it is best to reuse it through inheritance. Sometimes, it may be better to start on an entire new leaf and sometimes, turn over a new forest. This is the second article in the series that Justin Lovell will publish over the next few weeks.
by Justin Lovell
Average Rating: 
Views (Total / Last 10 Days): 23210/ 103

If the first article, The Basics of Server Controls, we briefly went over how the user interface in ASP.NET is operated. We also discovered that everything that is parsed in an ASP.NET page is control, or is converted/parsed as a control. However, we looked at a sample which demonstrated that we just reused the Label control. Although not much detail was discussed on the reuse of the Label control, we will discuss that in this article.

As you probably know, the minimal inheritance that you require to create a server control is for the class to inherit (directly or indirectly) from the Control class in the System.Web.UI namespace. Other controls inherit from here but the most other important (or noteworthy control) is also the WebControl class which is found in the System.Web.UI.WebControls namespace. Almost all of our everyday used control that is built-in into the .NET Framework inherits from this class/control.

However, when it comes down to creating our own server controls, we are always faced with decisions of where to start off. We sometimes see a control that we want to modify functionality or behaviour of the normal control. Sometimes, building controls from scratch is the best option but there is still the choice of whether to use the Control class or WebControl class. I will discuss some of the advantages of going each route in this article and look at how each one is achieved.

View Entire Article

User Comments

Title: AddAttribute/RenderBeginTag sequence   
Name: Kevmeister
Date: 2005-12-08 8:50:14 PM
Shouldn't the AddAttribute calls be executed *before* the RenderBeginTag?
Title: Sockets   
Name: Madhusudan
Date: 2004-09-08 8:37:47 AM
I need to distribute a control that enacpsulates the socket class. Is it possible to inherit from the socket class and write a custom web control ?
Title: Re: composite control   
Name: Justin Lovell
Date: 2004-08-24 1:23:42 PM

I have already written an article on the basics of databinding for server controls. You can read this information from here:

And if you want to see how the templates part work out, then you can also read another article that I have written over here:
Title: composite control   
Name: Senthil
Date: 2004-08-24 9:16:32 AM
I need to create a user control i want to assign various properties to it ,all the text propeties etc are felt easy to me,but i need to bind the database to my serve control and retrive data to that as like how the boundcolumn hav dataTextField like that i want to create and bound my data to the struggling to it for the past wk's can u help me regd this

Product Spotlight
Product Spotlight 

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

©Copyright 1998-2024  |  Page Processed at 2024-05-27 8:10:24 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search