Using a Control Adapter for Branding SharePoint Web Parts

One of the requirements I see appear over and over when working with custom SharePoint deployments is the need for medium to complex branding.  In the case of an intranet deployment the branding usually is more basic and functional.  Possibly some minor master page changes, a new set of styles, and replacing some images is all that is required.   When it comes to public facing SharePoint sites the branding suddenly can become much more complex.

With public facing sites it seems that completely new master pages, page layouts, styles, images, web parts and dynamic content (jQuery, Ajax, etc…) is required.   Most of the branding efforts are pretty straight forward.  The difficult part can be branding the out of the box SharePoint web parts.   If you have ever tried to do something fairly common such as adding full 4 rounded corner effect to a web part you will find that it can be a difficult if not impossible.   This is because the out of the box web parts have very limited CSS classes defined, and without those CSS classes we will have a very tough time creating a cross browser style to match our designers intention.   This is where control adapters come in and can help.

A control adapter is a simple class that when applied can override the rendering of any web control.   Using a control adapter we can easily wrap additional HTML tags with CSS classes around the out of the box web part so we can get the full 4 rounded corner effect our designer was after.

Creating a control adapter is simple.  Start with a single class that inherits from the ControlAdapter base class.   Override the Render method and implement your own rendering basing it on the original controls rendered content.   Once you have a control adapter compiled with a strong name it can be deployed as part of a SharePoint solution package.   With a little bit of custom code behind your master page you can easily apply the control adapter to selected out of the box SharePoint web controls.

In an upcoming blog post I will go into detail on how to create a control adapter and how to register that for use with SharePoint.

0 thoughts on “Using a Control Adapter for Branding SharePoint Web Parts”

  1. Hi; I””ve started to dabble in control adapters, but mostly have been using ones available out there, like CSSFriendly. Looking forward to your next post to get tips on how to write my own! Please post soon!

Leave a Reply