CompositeControl Base Class in ASP.NET 2.0 (a new alternative to UserControls)

I stumbled across an interesting blog post on Ian Blackburn's blog tonight.  On it he shows a simple sample of how to use the new CompositeControl base class that is provided with ASP.NET 2.0.  CompositeControl dramatically simplifies the work needed to create a re-usable ASP.NET custom control. 

Ian raises the interesting question of whether this is now a better option to use instead of UserControls (.ascx files) for building re-usable controls for your projects.  A couple of advantages they bring:

  1. The ability to define UI templates (for example: like the <ItemTemplate> property of a Repeater or DataList)
  2. The ability to provide richer design-time support (wizards, property editors, smart-tasks, etc)
  3. The ability to add to the VS Toolbox
  4. The ability to package up and re-use without having to copy the .ascx into a project, as well as to embed resources (for example: images) inside the control assembly

They do require a little more work (and don't have a WYSIWYG designer like usercontrols do), but the above advantages are compelling.  One other built-in feature in VS 2005 and Visual Web Developer is that .aspx intellisense for controls (both compiled controls and user-controls) is now automatically generated for you -- so as a control developer you no longer have to jump through hoops to enable this (instead the editor can provide this automatically through reflection).

Here are a few good tutorials I found on the web that discuss how to use the CompositeControl approach more if you are interested in trying it out:

Hope this helps,


P.S. Note that UserConrols in VS 2005 and Visual Web Developer *do* now support showing up in WYSIWYG mode instead of being the ugly grey box they were in VS 2003.  So that is one big gain that UserControls picked up in VS 2005 (just to help make the debate of which to use harder <g>).



  • Hi Scott,

    thanks for mentioning my article :-)

    I agree,the CompositeControl is a great addition for all Control developers. But you forgot to mention the CompositeControlDesigner class, which really takes all the hassle out of creating a designer for a templated control.

    Also, I am curious about the .aspx Intellisense support that you mention. I don't seem to get that default for my controls. Is there any attributes I have to include, or some method that needs overriding to enable this?

  • Good post Scott...are you planning to bring these two worlds together in a future release?

  • Hi Saikat,

    Can you send me an email that describes this problem better? I can then help loop in someone who can help.



  • How should be design a base class for a very complex composite control in 1.1 ..
    I am looking for some best practice..

  • Hi I Need to develop a composite control with controls toolbar, list & tree list. Toolbar will have dropdown of actions which will change contents of the list.
    I need some best practice guidelines. ( 1.1).


Comments have been disabled for this content.