Download source
When creating web applications with ASP.NET developers will usually create User Controls or Custom Server Controls. User Controls have the ASCX extension and allow developers to group together ASP.NET controls and functionality into a reusable control. Custom Controls are a bit more complex and require the developer to define the html that the control generates as well as all it’s functionality. It is also possible to add child ASP.NET controls to a Server Control and have the control render those child control and maintain their viewstate with little work.
In .NET 2.0 the abstract CompositeControl class was introduced, which is derived from WebControl but also uses the interfaces INamingContainer, which makes sure all child controls have a unique ID, and ICompositeControlDesignerAccessor which is used to allow the control to render the control automatically at design time based on the child controls. The CompositeControl also ensures that child controls are always created which saves using the EnsureChildControls method that many Custom Control developers will be familiar with.
In this post I’ll explain how to create a simple Composite Custom Control and how to customise the HTML that it renders.


