views:

397

answers:

2

I have like 10 aspx pages (junior_class_students1.aspx-...10.aspx). They all have the same master page in the back (class_students.master). Everytime i load a page i want the master page background-color to change, to the one that i can specify per page. so ...students1.aspx then .master ...students2.aspx then .master ...students3.aspx then .master

how can this be achieved?

A: 

CSS classes.

You could place a div that fills the body inside on body and contentplaceholder.

Master Page

<body>
<asp:ContentPlaceHolder id="cph" runat="server" />
</body>

That div could have a uniuqe ID per page.

Cntent page

<asp:Content id="cnt" ContentPlaceHolderID="cph">
    <div id="Page1" class="container">
      <!--Page Content-->
    </div>
</asp:Content>

Then CSS could be something like:

div.container
{
    width: 100%;
    height: 100%;
}
div#Page1
{
    background-color: green;
}
div#Page2
{
    background-color: blue;
}
...
Dustin Laine
wait. on the second piece of code for id="cnt". that goes in the content pages, in my case ..students1.aspx , 2,3... Now if i give a div out there for 100% height and width, how would that make the master page body change color?
fered
What I am getting at is that you should place the div to fill the entire body. You could put the body in the content page, but I prefer having the form in my master page.
Dustin Laine
+1  A: 

Keep in mind that content holders can go anywhere in the page. It's possible to do something like this:

<div style="background-color:<asp:ContentPlaceHolder id="divColor" runat="server" />"></div>

And then in your page have this:

<asp:Content ID="divColorContent" ContentPlaceHolderID="divColor" Runat="Server">green</asp:Content>
Bob
im confused.. this is going to change the body color of master page when every new page loads?
fered
+1 Nice solution Bob!
Dustin Laine
The master page and the page that uses it are the same page. ASP.NET combines them into a single page. The above will ultimately turn into one page that has <div style="background-color:green"></div>
Bob