.NET Tip of The Day
Learn one new .NET trick every day
Быстрое пополнение счета телефона      Login or Join

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

Comments:

The latest version of Microsoft's CSS adapters is now an open source community effort. Check it out at http://www.codeplex.com/cssfriendly

Brian 4/10/2008 11:26:17 PM

Name
URL
E-mail
Provide your e-mail address to receive notification about new comments.
Message
HTML tags are not supported.
Please add 1 and 7 and type the answer here:
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.