CSS Adapters in .net are rarely used, even though they are really powerful and can fix things like xhtml validation errors. This very quick sample will show you how to replace the <span> tags with a <div>

Create a class file, something like “LabelOverride.cs”, and put in the following:

using System.Web.UI;

namespace CSSAdapterTest
public class LabelOverride : System.Web.UI.WebControls.Adapters.WebControlAdapter
protected override void RenderBeginTag(HtmlTextWriter writer)
protected override void RenderEndTag(HtmlTextWriter writer)

Create a folder in the web application called “App_Browsers”, and create a .browsers file called “CSSAdapter.browser”, and enter in the following:

<browser refID="Default">
<adapter controlType="System.Web.UI.WebControls.Label"
adapterType="CSSAdapterTest.LabelOverride" />

This basically tells asp.net to override the controlType’s renderer with the one you have specified.

Once you have done this, and when you build your application, all <span>’s will disappear and be replaced with <div>’s!

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • DotNetKicks
  • DZone