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.
Popular Articles
Last viewed:
- Configure FTP Server on Windows 2003 Server
- Add a Composite Control to the Visual Studio Toolbox
- Data Access Layer using SqlDataReader and C#
- Change Password Policy on Windows 2003 Server
- Installing an SSL / TLS certificate on Windows Server 2008
- Global.asax Events in IIS 6 and IIS 7 for Static Resources

Recent comments
8 hours 45 min ago
23 hours 37 min ago
3 days 11 hours ago
4 days 11 hours ago
6 days 12 hours ago
1 week 2 hours ago
1 week 12 hours ago
1 week 18 hours ago
1 week 22 hours ago
1 week 3 days ago