Background images don't show in Master Page when changing directory

Last post 08-29-2008 11:51 AM by Dave Sussman. 5 replies.

Sort Posts:

  • Background images don't show in Master Page when changing directory

    08-29-2008, 4:44 AM
    • Member
      4 point Member
    • tiestodj
    • Member since 07-31-2008, 8:41 AM
    • Posts 7

    Quite simply,  I would like to know how to set up a Master Page so that a background image in a table cell will always point to the correct Image path.

    Currently I have a web site with a Master Page at the root and two folders, called Images and Games.  Using a tilde ~ with the <asp:Image> image url path the page automatically makes sure the correct directory is pointed to in the source code.

    In my source code the following image points to this path when a page in the root folder is loaded:
    <img id="ctl00_Image1" src="/Images/logo.gif" style="border-width:0px;" />
    and when loading a page in the Games folder it changes to this in the source code:
    <img id="ctl00_Image1" src="../Images/logo.gif" style="border-width:0px;" />

    ..which is all fine - the correct image regardless of the current directory.

    However, how on earth do you do the same for background images in a table cell?

    For example in the root folder the following cell correctly displays the background image on the Master Page:
    <td background="Images/background.gif" height="29">
    but view a page in the Games directory and it just stays the same:
    <td background="Images/background.gif" height="29">

    ..obviously meaning its now pointing to the wrong directory now, it hasn't updated automatically like the above image control.

    Can someone tell me the correct way of dealing with this please?  I've read you can't use the ~ for background images?  So what's the solution?

    Thanks in advance,
    A (still) asp.net noob!

  • Re: Background images don't show in Master Page when changing directory

    08-29-2008, 8:53 AM
    Answer
    • Contributor
      2,041 point Contributor
    • liammcmullen
    • Member since 03-24-2008, 3:31 PM
    • Belfast
    • Posts 353

    see if this helps

    in the aspx file replace your body tage with 

    <body background=<%= ResolveClientUrl("background.gif") %> >

    or if your using CSS

    body
    {
    background-image:url('images\background.gif');
    }

     

    good Luck,

    Liam

     

    Liam Mcmullen
  • Re: Background images don't show in Master Page when changing directory

    08-29-2008, 9:36 AM
    • Member
      4 point Member
    • tiestodj
    • Member since 07-31-2008, 8:41 AM
    • Posts 7

    Unfortunately this doesn't work.

    I am also using CSS to place a background image in a table cell in the master page but the path is wrong when a page in another directory is loaded.

    Surely there's a way around this, I can't be the first person to come across this problem!?

  • Re: Background images don't show in Master Page when changing directory

    08-29-2008, 11:06 AM
    Answer

    If you use CSS and background-image, then the image references is always relative to the location of the CSS file, irrespective of what level in a folder hierarchy that CSS files is used from. So just set up your images ones, relative to the CSS; I keep my CSS files in a "Stylesheet" folder and images in "Images". Therefor I can do url(../Images/foo.gif) and know it will always work.

  • Re: Background images don't show in Master Page when changing directory

    08-29-2008, 11:41 AM
    • Member
      4 point Member
    • tiestodj
    • Member since 07-31-2008, 8:41 AM
    • Posts 7

    D'oh!  I've been a humungous fool.  I didn't notice the incorrect path to the images in the CSS file.  I've probably tore most of my hair out needlessly over this, what a bloody banana.  Thanks all!  No doubt I'll be back on here soon..!

  • Re: Background images don't show in Master Page when changing directory

    08-29-2008, 11:51 AM

    The stupidest errors take the longest to fix. Welcome to my life.

Page 1 of 1 (6 items)