SharePoint Branding Issues: Web Parts

This final blog post (for now) in the SharePoint Branding Issues series is one regarding web parts and their branding issues. I’m assuming most of you know what web parts are. They are like mini applications within a web page. As they are so small, you’ll often add several of them together on the same web page. In other technologies, such applications are called widgets or gadgets or whatever. But basicly, their ideology is the same. A nice example is featured on live.com.

To get back to .NET, web parts are a new technology within ASP.NET (and unified in version 2). In previous versions of SharePoint, they used some custom made framework. And now in WSS 3.0, they are slowly migrating to the new ASP.NET 2 standard, which allows far more easy web part development. Finally to be complete, a few more statements regarding web parts. Web parts are placed within horizontal or vertical web parts zones. These zones can define the chrome style used for the web parts within. The web part chrome, for those who do not know, is a fancy word for its border decoration. Furthermore, the web parts need one single web part manager, per page, for.. well.. managing purposes. Finally, all of these concepts have a corresponding class within the System.Web.UI.WebControls.WebParts namespace. And basicly this is, in a nutshell, what web part infrastructure is all about.

Now, the thing with SharePoint. They decided to overwrite all of these classes (just as we would for a custom branding job in ASP.NET). But somewhy they made the decision to make the new classes all sealed. So basicly you can not change anything, except, of course, if you rewrite every single class… :-) I know… And as one of my hungarian colleagues would say in such a situation: nice! ;-)

The chrome in SharePoint consists of 5 fixed chrome types (Default, None, Title and Border, Title Only and Border Only). These are implemented in an internal SPChromeHelper. What this class does, is adding the following structure as chrome:

<table>
    <tr>
        <td>
            <table>
        </td>
    </tr>
    <tr>
        <td>
            <div>
        </td>
    </tr>
</table>

Depending of the style the first row, which is the header, will be generated or not. Accordingly CSS classes are attached to the rows, the inner div and the inner table. As you can imagine, this kind of structure can be really restrictive. It is very difficult to add gimmicks, like rounded corners, to such a composition.

What can we do then? Well, basicly, applying tricks and hacking our way in. To achieve this, once again, our friend is CSS. By adding some classes to the right place and by using some specific CSS selectors, one can manage to achieve some degree of customization. A possible solution could be to add a specific CSS tag name to the declaration of the zone tag in your page. This way you can reach its inner web parts through the use of CSS selectors. In most cases you can define your own zones, so this can potentially be a solution for the problem. Another, more obvious solution, consists of simply overwriting the fixed chrome type’s CSS styles. The issue here is that every web part has to be set with the correct fixed chrome type to display your customizations. Of course, you still have the same limitations as the previous solution, as the structure of the chrome is still the same. More over, you usually cannot reach all generated HTML tags using only the fixed CSS class names.

While writing this article, I found this post written by Daniel Terborn. Daniel tackled the same problem and supplied another possible solution. He decided to create a base web part which implements all of the layout. Finally, with some CSS hooks, he manages to get really nice web parts. The problem with this solution is that it only applies to custom written web parts. In some situations this can be acceptable (by only using custom web parts), but most of the time you’ll want to use the out-of-the-box web parts too, for obvious reasons.

Conclusion? There is no clean and neat solution for web part branding within the current iteration of SharePoint products. We can only hope the sealed classes will be opened up in future versions. Until then, happy SharePointing.

10 Responses to “SharePoint Branding Issues: Web Parts”

  1. Links (11/13/2007) « Steve Pietrek’s SharePoint Stuff Says:

    [...] SharePoint Branding Issues - Web Parts [...]

  2. SharePoint, SharePoint and stuff : Artikelserie zum Thema Probleme bei der Anpassung Says:

    [...] SharePoint Branding Issues: Web Parts [...]

  3. Joe Says:

    I am just starting a branding project and googled across this article. It was very helpful, thanks a lot!

    Just a quick questions… the chrome structure you presented… the and tags inside the table columns seem out of place. Where are the closing tags? Is this correct?

    Thanks!

  4. Tombo Says:

    Hi Joe,

    The tags are indeed not closed. I just wanted to point out SharePoint is using a table for the title area and a div for the actual content area. Consider this figure more like a quick structural overview (mockup) of a webpart rather than the exact composition of its structure.

    Hope this clarifies! :-)

  5. Daniel Terborn Says:

    Thanks for referring to my little custom web part solution. It’s possible to apply a chrome to standard web parts by wrapping them using my base class, but boy is that an annoying solution. :-)

    I’m quite curious of how far you have come with your solution. Can you do rounded corners, shaded borders and so? Especially while beeing IE6 compatible?

    Btw, ran this problem with some Microsoft employees – and I am still waiting for their final conclusion, but their primary answer to me was… that the solution I implemented is the right way to do it. Damn. I thought they’d have a better solution at hand.

  6. Tombo Says:

    Hey Daniel! No problem, man. You deserve the credit. It would be a nice extension to your solution if you could make the webpart generic (colleagues of mine are probably already smiling when seeing “generic” as I am quite the generic man.. :p) What do I mean by this? Well, this generic web part would have a tool part panel where you can select which other webpart type to encapsulate. This solution would tackle the problem of the out of the box webparts, but you’d still have problems with the webpart menu, I think.

    For my solution, well, it doesn’t offer a nice solution for rounded corners. Rounded corners techniques need at least two nested containers which are css tagged. This is not the case with web part zones. Maybe you could achieve it with some tricky CSS selectors to reach the TD’s.. but you’ll have to make sure the style is not applied to inner TD’s in the webpart. I personally have not tried it.. yet.. :p

    Another solution could be CSS adapters. These can capture the html outputted by SharPoint and parse them before sending them (modified) to the client. Needless to say this technique has a serious performance hit.

    Btw the answer of the Microsoft folks does not really surprise me.. ;-) It’s a solution, but as you say, we kinda ‘d like a better one from them. :-)

  7. MDL Says:

    You can have the web part header customized with rounded corners like this: http://madalina.blog.com/2705257 For all the webparts, not just your custom ones.

  8. Tombo Says:

    Hi Madalina.

    This is indeed a very nice solution and can be workable in numereous situations. :-)

    Two remarks though:
    - this method won’t work for a user who’s not allowed to edit webparts. eg. a reader
    - you cannot use this method if you want 4 rounded corners

    Nevertheless, great job! If you have a final design, feel free to post the link. It’s always nice to see how people around the world manage to circumvent SharePoint’s shortcomings.. :p

  9. Amit Lohogaonkar Says:

    We have colleagues web part in person.aspx in mysite.
    When user adds new colleague with showto settings as “onlyme”, user himself can not see new colleague in colleagues web part. But when user clicks on manage colleagues link then he can see colleague in manage colleagues but not on colleagues web part. Also “asseenby” option is set to”everyone” which does not allow to select “onlyme” option.
    When showto settings is changed to “everyone” then only user can see added colleague in colleagues web part. Does anybody has solution for this issue? Let me know about it.
    Amit Lohogaonkar
    Amitmcpmcad@yahoo.com

  10. Tracy Says:

    SharePoint rounded web parts – http://www.signaturesterling.com/blog/post/Rounded-Corner-Web-Parts.aspx.

Leave a Reply