Developer

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!

About

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

Editor's Picks