Building Composite Server Controls
page 2 of 6
by Justin Lovell
Feedback
Average Rating: 
Views (Total / Last 10 Days): 35842/ 116

Should I compose controls with user controls?
Composition of controls is easier to do with user controls. I do take the following into consideration when I decide whether or not to use a server control to compose a collection of controls:
  • The composition will be unique to that project and will be a specialized exception.

  • The composition will be used under one application domain.

  • It is not planned to be extended. User controls are not easy to extend at all.

For me, all of the above must evaluate to “true”. Essentially, it is a weighing decision of which path to go – the only advice that I can give you is to plan ahead. But before I go on, I am going to hold this thought with you, the decision also totally depends on what type of programmer you are (I am going to discuss the major differences in composition between user controls and server controls).

The major difference is if you are inclined and attracted to raw source code (some people use the terminology, code-behind). So if you are more attracted to the following code:

protected Image image = new Image();
protected Button button = new Button();
protected override void CreateChildControls() {
   Controls.Add(image);
   Controls.Add(button);
}

Over this type of source code:

<asp:Image runat="server" />
<asp:Button runat="server" />

Then composing server controls is for you. Another consideration is to decide how pressed you are for time – server controls take generally “longer” to create and is easier to extend while user controls are “shorter” to create and is harder to extend. Again, this is where the weight scale comes in the picture.


View Entire Article

User Comments

Title: Template server control   
Name: cash
Date: 2010-04-14 1:32:41 PM
Comment:
plese give use simple eg. with property
Title: DP   
Name: Dharmendra
Date: 2010-01-06 2:55:06 AM
Comment:
Thanks a lot. One of the best, I have read on net.
Title: Nice but a little-bit of misinformation   
Name: Mike Walters (EventBookingDev)
Date: 2007-11-06 1:34:55 PM
Comment:
just a footnote here but if you are subclassing from Table (as noted: Table, INamingContainer) .. then you do not need to override the "TagKey" property. The only time you would need to do that is if you were subclassing from CompositeControl(in which you would not need INamingContainer either) or attemping to change the rendered output from say Table to Panel(div).
Title: Nice explaination   
Name: hiten Bawni
Date: 2007-08-22 9:23:30 PM
Comment:
At least it was better then the examples provided on Microsoft's web sites.

Good job!!
Title: Control Naming Error   
Name: Jon^2 S. Pascua
Date: 2007-07-22 11:07:45 PM
Comment:
Hi,

In the Interactive Composition example you provided, the controls are instantiated as SearchText but used as SearchTextBox

protected TextBox SearchText = new TextBox();
..
SearchTextBox.Width = Unit.Percentage(100); (and etc.)

Nice article though. Great Job!
Title: how can i put backroud image   
Name: Ekrem Keçeci
Date: 2006-11-08 7:47:46 AM
Comment:
i wanna put backround image from code. but i don't know what should do.
Title: Complete Article   
Name: Saakshi
Date: 2006-04-17 11:06:33 AM
Comment:
Excellent Articles
Title: I like it   
Name: sid76
Date: 2005-06-22 3:31:14 PM
Comment:
Nice.. Brings together all the information I need. Overall well written, I think I spotted one spelling mistake in this artical.. search the doc for "tow".

Keep it up, I understand now.
Title: Excellent...   
Name: m1k4
Date: 2004-07-31 8:39:44 PM
Comment:
Very detailed tutorial which helped me to (finaly) understand Composite Web Controls in ASP.NET.

Thank you very much

Product Spotlight
Product Spotlight 





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


©Copyright 1998-2020 ASPAlliance.com  |  Page Processed at 2020-07-04 8:53:39 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search