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.