Monday, March 31, 2008

ASP.NET 2.0 CSS Control Adapters for CSS friendly HTML output


This blog post summarizes a very differenbt concept that probably you might have not heard of. This is ‘ASP.NET 2.0 CSS Control Adapters’.

We know that every ASP.Net controls render there own HTML to show themselves. There are few incidents where you might have thought of to get rid of change the default generated HTML. For e.g For Locking GridView Headers etc. In such cases this is the solution. So if you have tired of having html <table> elements rendered by the built-in ASP.NET server controls and wishing you could use a pure CSS solution instead, solution is ‘CSS Control Adapters’.

These adapters take advantage of a new extensibility feature in ASP.NET 2.0 that we call the "Control Adapter Architecture", and which enables developers to override, modify and/or tweak the rendering output logic of an existing server control (without changing any of its properties, supported events, or programming model).

We can download the ‘CSS Control Adapter toolkit’ which provides pre-built control adapters for 11 of the most common ASP.NET controls (GridView, DetailsView, FormsView, DataList, Menu, TreeView, Login, LoginStatus, CreateUserWizard, ChangePassword and PasswordRecovery). The toolkit includes both VB and C# source code for all of the above control adapters. You can use the source-code as-is (without having to modify anything) to get pure CSS output. Or if you want to tweak the output even further you can go in and modify the adapters to emit any custom markup you want.

Use the link to How to use the CSS Adapters.

Control Adapters are classs that derive via the System.Web.UI.Adapters.ControlAdapter base class, and which implement rendering methods that allow a control adapter to completely customize how the markup of an individual control is rendered. We can customize different control adapters for different browsers if you want, or just define them for "Default" to apply them by default to all browsers that visit your app.

Thanks & Regards,

Arun Manglick || Tech Lead |

No comments:

Post a Comment