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.
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:
- 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.
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.
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.
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!