views:

1438

answers:

4

Is there away to set a background image on a webpage when the webpage is based on a masterpage. Notice its not the background of the masterpage i want to change, but the background of the page which use the masterpage.

+3  A: 

You can just add a style rule for body{} or whatever on the actual ASPX page. It will override any style set at the master page level.

edit: example:

<%@ Page Title="Example" Language="C#" MasterPageFile="~/MasterPages/Main.master" 
    AutoEventWireup="true" CodeBehind="TroubleShootScanning.aspx.cs" 
    Inherits="SpectrumTechnologies.TroubleShootingScanning" %>

<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" runat="server">
    <style type='text/css'>
        body { background-image: url(images/bgimage.jpg); }
    </style>
    <!-- the rest of the page here -->
</asp:Content>

This will override any values set in a stylesheet.

goldenratio
Can you please give me an example on how to use a style rule
CruelIO
+2  A: 

You could put a content placeholder on the master page that is within the header.

Then in your content page, put a content control where you could include the second modified CSS stylesheet or STYLE block directly.

HackedByChinese
I should state that I can't stand CSS randomly scattered throughout the document or attached directly to elements.
HackedByChinese
+1  A: 

There's an additional trick to add to this...(Second line below) Also helps the background show while testing locally.

<%@ Page Title="Contact" Language="VB" MasterPageFile="~/MyDefault.master" Theme="MyMain" %> <%@ MasterType VirtualPath="~/MyDefault.master" %>

msftwise
+2  A: 

I suggest adding an <asp:ContentPlaceHolder ID="ExtraStyles" runat="server" /> tag to the header of the Masterpage. That way you can add the following to your page:

<asp:Content ID="ExtraStylesContent" ContentPLaceHolderId="ExtraStyles" runat="server">
  <style type="text/css">
  body {background-image:url('someotherimage.jpg');
  </style>
</asp:Content>

By adding an extra ContentPlaceHolder you won't get the scattered style tags, they will end up in the head tag of the rendered html.

Colin
Very good solution.
goldenratio
This is the way I always do it, use it for adding page specific JS files as well, and mettags also (i.e. I am on a product page and I want to alter the default meta tag keywords / description)
Colin