Override Default SPAN Tag for Composite Controls

When creating a composite control in ASP.NET, by default, the main container tag that holds all of your controls and HTML is output as a SPAN tag.  One of the issues with this default behaviour is that SPAN elements (at least according to the standard) are "inline" elements.  As opposed to something like "DIV" elements which are "block" level elements, SPAN tags are inline and should only contain other inline elements.  So if you are adding any block level elements to your composite control, in order to be aligned with standards (and also to assist with layout on most new browsers), you may want to override the default output tag and change to to a DIV.

To change the default output tag in the composite control, you need to override the TagKey property.  Override the TagKey property with the following code:



/// <summary>
/// Makes it so this control is a "div" element instead of the
/// standard "span" element.
/// </summary>
protected override HtmlTextWriterTag TagKey
{
    get { return HtmlTextWriterTag.Div; }
}

If you want to read more about inline and block level elements, you can see the W3C's description here: 

http://www.w3.org/TR/html401/struct/global.html

Now when you run the code that uses your control, you will see that a "DIV" element has wrapped all of your HTML output for this control instead of a SPAN tag.