I have 10 pages and each body tag has its own class because of different background images on them. I was wondering how to do it in the master master page so that the class on the body tag when a new page is created is correct.


If I'm understanding your question correctly, you have 10 different types of pages in which the content area or body have specific classes depending on that content. A master page isn't going to get you the desired results. You'll want to have varying page layouts for that. Each page layout can have it's content area defined with your appropriate class so that you get the desired effect.

  • exactly sir the classes will be different layouts in every page – user555600 Jul 21 '11 at 0:14

It sounds as though what you are trying to do is generate unique content on each page but do it through the master page.

This is the wrong approach. Use your master page for elements of your branding that are consistent across all your pages. Of course because of the position of the body tag in your page element hierarchy you can't have that defined in the page.aspx, so you will need to define your background image some other way. This is a question for a CSS expert, but I would suggest, in your master page, using a single class for your body element (if you need one at all), and associating the particular image with that class in the page.aspx file. This could be something like a STYLE element or a link to a particular small CSS stylesheet.


I suggest using the same class, but override it in the specific pages, i.e. give the body tag a classname, then in the pages themselves override say the background-image property of this class. Since CSS is cascading the last read value will be used.


use jquery:

var url = location.search;
if (url.indexOf('/page-1.aspx')>= 0) {


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.