Click here to Skip to main content
13,300,654 members (52,840 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 12 Dec 2010

Why is my WebPart so Ugly?

, 19 Dec 2010
Rate this:
Please Sign up or sign in to vote.
Apply the current Theme to your WebPart
Have you wondered why the custom webpart does not follow the current themes? Well, there is a easy way to apply this; however the tricky part is to know the "Class Name".

Here is the code to load the Theme in CreateChildControls():

String themeCssUrl = SPContext.Current.Site.OpenWeb(SPContext.Current.Web.ID).ThemeCssUrl;
CssLink cssLink = new CssLink();
cssLink.DefaultUrl = themeCssUrl;
this.CssClass = "ms-WPBody";

Refer here: Cascading Style Sheets Class Definitions for Windows SharePoint Services

Following are the styles that are applied for a WebPart:

Area around the menu in Web Parts.

Title of a Web Part.
.ms-WPTitle A:link, .ms-WPTitle A:visited
.ms-WPTitle A:hover

Border around a Web Part when the part is selected.

Contents of a Web Part.
.ms-WPBody TABLE, .ms-TPBody TABLE
.ms-WPBody A:link, .ms-WPBody A:visited
.ms-WPBody A:hover
.ms-WPBody th, .ms-TPBody th
.ms-WPBody TD
.ms-WPBody h1, .ms-TPBody h1
.ms-WPBody h2, .ms-TPBody h2
.ms-WPBody h3, .ms-TPBody h3
.ms-WPBody h4, .ms-TPBody h4
.ms-WPBody h5, .ms-TPBody h5
.ms-WPBody h6, .ms-TPBody h6

Border around a Web Part.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Adhish Pendharkar
Architect AdhiMarg Technologies Ltd.
Hong Kong Hong Kong
Resident of Hong Kong, TOGAF 8 certified architect with over 15 years of international experience in the IT industry. Exceptional exposure to the marine / shipping technologies and knowledge of large scale database system architecture, enterprise systems design and work flow implementation.

You may also be interested in...

Comments and Discussions

GeneralMy vote 5 for good work! Pin
Abdul Quader Mamun17-Dec-10 6:23
memberAbdul Quader Mamun17-Dec-10 6:23 
GeneralGood work Pin
Abdul Quader Mamun16-Dec-10 9:46
memberAbdul Quader Mamun16-Dec-10 9:46 
GeneralReason for my vote of 5 Excellent Pin
Member 313707816-Dec-10 0:55
memberMember 313707816-Dec-10 0:55 
Reason for my vote of 5
GeneralReason for my vote of 5 nice idea Pin
rokarthik13-Dec-10 22:45
memberrokarthik13-Dec-10 22:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 19 Dec 2010
Article Copyright 2010 by Adhish Pendharkar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid