.NET Tip of The Day
Learn one new .NET trick every day
Login or Join
.NET Tips & Tricks Community RSS

Those who prefer reading this site through RSS now can also subscribe for updates to .NET Tips & Tricks Community.

How to change HTML markup produced by ASP.NET controls

There are at least two ways of changing HTML markup produced by standard ASP.NET controls. The most obvious one is to derive a new class based on an existing ASP.NET control class and override the necessary rendering methods.

Another option that is worth considering is to write a small control adapter for the existing ASP.NET control. This is a little chunk of logic that you add to your web site to effectively "adapt" an ASP.NET control to render the HTML you prefer. This approach has the following two major advantages over custom controls:

  1. You don't need to add the @Register directives to your pages.
  2. The ASP.NET framework comes with a built-in means to apply the adapters to just certain browsers. When you build entirely new custom controls you have to write your own logic to handle browser detection to vary the response.

For example you can use ASP.NET 2.0 CSS Friendly Control Adapters package to generate CSS friendly markup from some of the more commonly used ASP.NET controls.

4/9/2008
RSS .NET Tip of The Day
Subscribe to receive one tip from the .NET Tips and Tricks Community per day.
Previous Tips of The Day
The best of the .NET Tips & Tricks Community.
.NET Practitioners .NET Tips & Tricks Community
Every .NET practitioner has a trick up in their sleeve. This is the place to share it with other .NET people.
Submit a Tip
Discovered a new trick? Share it with others.
My Tips
Manage tips you authored.