2

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.

4 Answers 4

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Can you please give me an example on how to use a style rule
2

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.

1 Comment

I should state that I can't stand CSS randomly scattered throughout the document or attached directly to elements.
2

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.

1 Comment

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)
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.