Control adapters V1.0

ASP.NET 2.0 has given web application developers a lot of improvements over 1.1 despite the buggy Development Environment. One of my favorites is the Control Adapter Architecture, this gives us the ability to change the way a control renders without going to the trouble of creating our own custom control to replace the control we want to tweak.

The process is actually very simple and the results can be extremely good.

One of the big applications for this is to implement a control adapter that will render markup that will be more CSS compliant or even rewrite the rendering so that instead of tables you render using UL and LI tags. In essence you get to take control of the rendered output rather than relying on what you get ‘out of the box’.

I won’t go into technical detail in this post as frankly there are better resources out there, but in order to take advantage of this technology all you need is an adapter file, simply a class that overrides the RenderContents method, this class needs to inherit the System.Web.UI.WebControls.Adapters.WebControlAdapter class.

Now you have part two of the two part partnership required to customize your control, part one is of course the control itself. To bring the two together we have a middleman that sits in the App_Browsers folder of your application. This .browser file contains the XML that maps the control to it’s adapter and is where a lot of the ‘magic’ happens. It’s possible, using this file, to map your control to different adapters depending on the browser ASP.NET knows to check the browser and will point the control to the correct adapter as required. The browser file contents look a bit like this:

    1 <browsers>

    2   <browser refID=IE6to9>

    3     <controlAdapters>

    4       <adapter controlType=System.Web.UI.WebControls.DropDownList

    5       adapterType=AlgSoftware.Web.Controls.Adapters.DropDownListAdapter />

    6     </controlAdapters>

    7   </browser>

    8 </browsers>

If you are interested in finding out more about this then I recommend you download the latest release from here, You may also want to read through Scott Guthrie’s latest post about the adapters, as always Scott has included loads of great info as well as all the links you’ll need to get on top of this technology and improve your applications.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: