Images from masterpage cant be seen on subfolders

Rate It (1)

Last post 01-17-2006 2:01 PM by SimonCal. 6 replies.

Sort Posts:

  • Images from masterpage cant be seen on subfolders

    01-17-2006, 8:25 AM
    • Participant
      976 point Participant
    • luisevalencia
    • Member since 08-11-2005, 1:28 PM
    • Medellin
    • Posts 258

    Hello, I have a website with a master page that has some backgrounds and images, I also have in that website a folder called protected and some subfolders called administrator, user and so on.

     

    I created some pages based on the masterpage inside these directories but I dont see the images.  Should I copy the images  inside each directory??

    MCPD ENTERPRISE APPLICATION DEVELOPER
  • Re: Images from masterpage cant be seen on subfolders

    01-17-2006, 10:58 AM
    • Participant
      1,855 point Participant
    • jhouse
    • Member since 09-28-2002, 8:06 PM
    • Northern California
    • Posts 372

    most likely the path you are using to load the images is not valid once you are in a sub-directory
    if your images are runat="server" then you can use the '~', i.e. '~/images/some_image.gif', this should load the images from the root of the web project no matter where the pages exist

    another option is to put all of your files into sub directories, have a default.aspx page that redirects to a /home/default.aspx page, then all of your UI can use relative paths to load your images '../images/some_image.gif'

     

  • Re: Images from masterpage cant be seen on subfolders

    01-17-2006, 11:19 AM
    • Participant
      976 point Participant
    • luisevalencia
    • Member since 08-11-2005, 1:28 PM
    • Medellin
    • Posts 258

    I tried to use two different way in the code of the masterpage

     

    <img src="../Imagenes/cabezote/GestionCompetencias2_01.gif" /></td>

    <img src="~/Imagenes/cabezote/GestionCompetencias2_02.gif" />

    <img src="Imagenes/cabezote/GestionCompetencias2_03.gif" /></td>

     

    The only image that was show was the third one

     

    I didnt understand the second option you gave me.

    MCPD ENTERPRISE APPLICATION DEVELOPER
  • Re: Images from masterpage cant be seen on subfolders

    01-17-2006, 11:37 AM
    • Participant
      1,855 point Participant
    • jhouse
    • Member since 09-28-2002, 8:06 PM
    • Northern California
    • Posts 372

    i prefer to use this style when referencing images
    <img src="../Imagenes/cabezote/GestionCompetencias2_01.gif" /></td>

    so then I set up my project file structure like this

    /admin/default.aspx
    /admin/manage_user.aspx
    /admin/etc....
    /home/default.aspx
    /home/contact_us.aspx
    /home/etc...
    /product/product_search.aspx
    /product/product_detail.aspx
    /images/all image files...
    /include/js, css, other files - maybe your master files?

    /default.aspx - this page has no UI, it redirects to /home/default.aspx
    the only file I have in the root is /default.aspx, everything else is in sub directories
    this makes the entire site very consistant in the way it references images, js, css, etc...

    if you don't have a site structured this way then using
    <img src="~/Imagenes/cabezote/GestionCompetencias2_02.gif" />
    proably makes the most sense as you do not need to worry your images references as they get loaded from the root of the web project

     

  • Re: Images from masterpage cant be seen on subfolders

    01-17-2006, 11:39 AM
    • Participant
      1,855 point Participant
    • jhouse
    • Member since 09-28-2002, 8:06 PM
    • Northern California
    • Posts 372

    this  <img src="~/Imagenes/cabezote/GestionCompetencias2_02.gif" /> should work if you add a runat="server" attribute, otherwise it ignores the ~

  • Re: Images from masterpage cant be seen on subfolders

    01-17-2006, 11:45 AM
    • Participant
      976 point Participant
    • luisevalencia
    • Member since 08-11-2005, 1:28 PM
    • Medellin
    • Posts 258
    Thanks , that tip helps a lot   
    MCPD ENTERPRISE APPLICATION DEVELOPER
  • Re: Images from masterpage cant be seen on subfolders

    01-17-2006, 2:01 PM
    • Participant
      1,910 point Participant
    • SimonCal
    • Member since 06-10-2002, 4:43 PM
    • Posts 381
    • AspNetTeam
      Moderator
    The "~" syntax is only a server-side (ASP.NET) notation. Therefore it'll only be treated by server-side controls. <asp: runat="server" or HTML intrinsics (Html element also runat="server"). Even if you use other notations, ASP.NET will re-base the Url reference automatically.
    Simon
    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 1 (7 items)