Embrace CSS with Friendly Control Adapters for ASP.NET 2.0

ASP.NET 2.0 CSS Friendly Control Adapters 1.0 provides another vehicle to move Microsoft's base development technology towards a standards-based approach to developing Web applications.

Even though Microsoft is not always the biggest advocate of standards such as CSS, there is robust CSS support in the latest incarnation of its Visual Studio environment, and CSS is easy to apply in ASP.NET applications -- but it could be so much easier. The goal of ASP.NET 2.0 CSS Friendly Control Adapters 1.0 is to simplify CSS integration with its controls, making it easier to change appearances via CSS.

Control Adapters

The control adapter architecture was added with ASP.NET 2.0. ASP.NET 2.0 provides an adaptive architecture that allows key life cycle stages of a control to be intercepted and substituted with custom behavior. A good example is intercepting the rendering of a control; that is, you may substitute your own rendering logic as opposed to the default HTML rendering for ASP.NET user controls.

This is the approach employed by ASP.NET 2.0 CSS Friendly Control Adapters 1.0. The Control Adapters assume control of the HTML rendering that is delivered to a browser. This is handled by overriding four methods within the control's code. The following list describes the methods:

  • OnInit: The initialization of the control. If the adapter is enabled, the necessary scripts (JavaScript) are registered for the control (via the RegisterScripts method).
  • RenderBeginTag: The rendering of the beginning HTML tag for the control. The necessary CSS class is assigned to the HTML tags, so it may be styled via associated CSS files.
  • RenderEndTag: The rendering of the closing HTML tag for the control.
  • RenderContents: The body of the HTML for the control is rendered. At this point, you may use custom HTML that overrides the default HTML for the control. A good example is the ASP.NET Menu control where HTML lists are used in ASP.NET 2.0 CSS Friendly Control Adapters 1.0 as opposed to the default HTML table markup.

The overriding of these methods is just one aspect of the approach used by ASP.NET 2.0 CSS Friendly Control Adapters 1.0. The architecture includes code files, JavaScript, and CSS files.

Why bother with ASP.NET 2.0 CSS Friendly Control Adapters 1.0?

You may be perfectly happy with the default behavior and appearance of the ASP.NET Web controls, but many developers scoff at the bloated and confusing table-based HTML generated by these controls. ASP.NET 2.0 CSS Friendly Control Adapters 1.0 allow you to avoid the dated use of HTML tables and firmly embrace a standards-based approach built on CSS.

Like most programming endeavors, there is more than one way to accomplish a task. With that said, many developers consider ASP.NET 2.0 CSS Friendly Control Adapters 1.0 overkill since they can employ such functionality by developing their own classes that extend existing controls and override the necessary rendering methods. This is a good point, but ASP.NET 2.0 CSS Friendly Control Adapters 1.0 architecture is easier to employ since there is no need to compile and develop the new controls nor is it necessary to register the controls on each page where they will be used.

Getting the code

ASP.NET 2.0 CSS Friendly Control Adapters 1.0 was originally made available via the ASP.NET Web site. In March 2007, Microsoft decided to allow the community to contribute to its development, so it was moved to its Codeplex site as a community project. There are two options for using the controls:

  • The project's assembly file is available via its own download (CSSFriendly.dll). This allows you to use the features in your project by referencing the assembly file and using CSS files.
  • The complete source code for the controls is available for download. This includes VB .NET and C# source code along with JavaScript and CSS files. This allows you to compile the functionality into your own applications.

You can choose your own download option with the assembly available as one file you copy to the appropriate place in your environment and the other available in a zip file.

Along with the JavaScript, CSS, and compiled code, ASP.NET 2.0 CSS Friendly Control Adapters 1.0 use a browser file to tell the Web site to always use the control adapters. You can configure it to use the adapters for specific versions of specific browsers only, but the browser file is necessary to use the controls.

More control

ASP.NET 2.0 CSS Friendly Control Adapters 1.0 provides a way to easily style ASP.NET Web controls via standard CSS that takes advantage of the controls adapter architecture introduced in ASP.NET 2.0. This architecture overrides the default HTML rendering of the basic ASP.NET Web controls with a standard approach that uses CSS, JavaScript, and .NET code (VB.NET/C#). The ASP.NET 2.0 CSS Friendly Control Adapters 1.0 download is another vehicle pushing Microsoft's base development technology towards a standards-based approach to developing Web applications.

Next week, I'll take a closer look at the controls in ASP.NET 2.0 CSS Friendly Control Adapters 1.0 download.

Offer your feedback

Are you using Web standards in your Web applications? Are you combining Web standards with Microsoft development tools? Share your thoughts and experience with the .NET community by posting to the article discussion.

Tony Patton began his professional career as an application developer earning Java, VB, Lotus, and XML certifications to bolster his knowledge.


Get weekly .NET tips in your inbox TechRepublic's free .NET newsletter, delivered each Wednesday, contains useful tips and coding examples on topics such as Web services, ASP.NET, ADO.NET, and Visual Studio .NET. Automatically subscribe today!


Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a productio...


As far as the article is concerned I would have to disagree with this statement ("but many developers scoff at the bloated and confusing table-based HTML generated by these controls"), not because its not true but just because it doesn't make since to do that. What I mean is this. If the server is generating the client markup then who cares if its confusing or bloated? Your not going to open the client code up in notepad anyway to edit it. Your editing is in the IDE and all you care about is the control. You can manipulate what the server control produces via server code anyway. The controls' markup is abstracted for a reason. The whole point of server controls was to not worry about the client markup. It was supposed to save a developer time. Worrying about the client markup defeats the purpose of using server controls in the first place.


If you have the time it takes to spend on making your .NET applications and websites completely W3C compliant then I think you could be spending your time more wisely. The benefit of W3C compliance is not a user based benefit and it takes too much valuable time IMO. It really only benefits developers. You could have a completely compliant website that still looks and acts jacked up in browsers other than IE. On the other hand, you can have a non compliant website and application that looks and functions the same in all browsers. So the majority of users do not benefit from compliance at all. General html and css standards are all that's needed to make a good application and website. I think a developer goes overboard with W3C standards. I cringe every time I see a website with the W3C standard compliance logo in the footer. What purpose does this serve other than blowing up the developers ego? If you say a user benefits from faster downloads then I say baloney! Most of the time its the server connections / server code that takes the time not the client code / markup. With most users on broadband anyway I feel server code compliance and optimization is way more important than wasting your time optimizing client code and markup. In the business world time and rapid application development is key to pleasing your boss. I know a lot of people who feel the way I do about this. Most just don't talk about it.


After reading the article, I'm still not clear what it does or how I can use it.


From what I get it seems transparent and once you include the dll in your app it does the work for you. You most likely have no other work to do but include the dll. I guess its primary purpose it to force the server controls to use divs and css instead of tables. What is the benefit of this? Well since the server has to perform a function via this new dll file I see no benefit. The time it takes the server to transform the client markup to divs, the client could have just downloaded the table markup. :-)

Editor's Picks