Img Source proglem

Last post 05-09-2008 2:48 PM by allanhorwitz. 18 replies.

Sort Posts:

  • Img Source proglem

    04-12-2008, 12:35 PM
    • Loading...
    • danishjee
    • Joined on 10-31-2007, 11:06 AM
    • Pakistani
    • Posts 59

    Hi ,

    I have problem with master page images which is not showing on my other pages.

    when i use this below code then image show me on master page but not show me on child pages.

    <img alt="" src="imgs/4.gif" style="width: 794px; height: 41px"/>

    and when i use this below code

    <img alt="" src="~/imgs/4.gif" style="width: 794px; height: 41px"/>

    then nothing show me on master page also...system said there is no image found..

  • Re: Img Source proglem

    04-12-2008, 12:39 PM
    Answer
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 6,852
    • Moderator
      TrustedFriends-MVPs

    since a masterpage can get used across any folder in your site, i prefer the root relative syntax ~/

    but you need to make the image a server control for that to work.

    <img id="img1" runat="server" 
         alt="" 
         src="~/imgs/4.gif" 
         style="width: 794px; height: 41px"/>
     

     

    Mike Banavige
    ~~~~~~~~~~~~
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Img Source proglem

    04-13-2008, 2:41 AM

    I too have this problem. I am using master page. The master page has layout using tables and has img (s) to left and right as border in td (s). If i change it to asp image controls, then i cant write anything in those cells as images will take the space. How can i make images as ASP image controls plus they appear in background of the text.

    Any idea??

  • Re: Img Source proglem

    04-13-2008, 6:43 AM
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 6,852
    • Moderator
      TrustedFriends-MVPs

    you can add images without placing an img tag on the page. assign a css class to your table cells and then using css you can set a background-image for the cell.

    Mike Banavige
    ~~~~~~~~~~~~
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Img Source proglem

    04-14-2008, 10:53 AM
    • Loading...
    • allanhorwitz
    • Joined on 04-10-2008, 1:45 PM
    • Philadelphia, PA
    • Posts 285

    Did you try?:

    <img alt="" src="/imgs/4.gif" style="width: 794px; height: 41px"/>

    -Allan

    Allan Horwitz
  • Re: Img Source proglem

    04-15-2008, 7:46 AM
    • Loading...
    • S.p
    • Joined on 01-18-2008, 10:59 AM
    • Posts 10

    Hi

    For such kind of problems its better to catch ur application's root path.

    For example ur application name is Sample and images r inside the folder img. i.e D:/Sample/

    You configure this value in ur web.config : <add key="approotpath" value="D:/Sample/">

    and while setting imageurl property use it as:

    defalut.aspx: <img id="img1" runat="server"/>

    default.aspx.cs: img1.src=ConfigurtaionManager.AppSettings["approotpath].Tostring() + "imgs/4.gif";

     Hope this works good

     

    S.p

  • Re: Img Source proglem

    04-27-2008, 5:05 AM
    • Loading...
    • danishjee
    • Joined on 10-31-2007, 11:06 AM
    • Pakistani
    • Posts 59

    hi,

    Would u plz write down with vb code im using asp.net with vb code.

     

    THANKS

  • Re: Img Source proglem

    04-27-2008, 9:17 AM
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 6,852
    • Moderator
      TrustedFriends-MVPs

    there is no code needed and hard coding your applications root folder in your web.config file is not recommended.

    server controls can automatically resolve the ~/ at the beginning of a path to be your app root folder.  So it you set your image controls to be runat=server and add the ~/ to the src, then your images will will all render with root relative src paths.  this means those image paths will be correct regardless of whether your master page is being call from a subfolder or not.

    This is all you need to do:

    <img id="img1" runat="server" 
         alt="" 
         src="~/imgs/4.gif" 
         style="width: 794px; height: 41px"/>
      
    Mike Banavige
    ~~~~~~~~~~~~
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Img Source proglem

    04-27-2008, 10:50 AM
    • Loading...
    • danishjee
    • Joined on 10-31-2007, 11:06 AM
    • Pakistani
    • Posts 59

    MR. mbanavige

    I already try to use ur way. with runat="server" ~ its not working..,

  • Re: Img Source proglem

    04-27-2008, 11:03 AM
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 6,852
    • Moderator
      TrustedFriends-MVPs

    then please show us what youve done and what result you got - because this is honestly the way to do it.

    show your aspx markup for your image and tell us what the resulting html was for that markup when your page rendered. 

    not the whole page... just the relevant pieces.

    Mike Banavige
    ~~~~~~~~~~~~
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Img Source proglem

    04-27-2008, 10:28 PM
    • Loading...
    • allanhorwitz
    • Joined on 04-10-2008, 1:45 PM
    • Philadelphia, PA
    • Posts 285

    mbanavige:

    then please show us what youve done and what result you got - because this is honestly the way to do it.

    show your aspx markup for your image and tell us what the resulting html was for that markup when your page rendered. 

    not the whole page... just the relevant pieces.

    That "~" sign may be the right way to do it, but in my experience, it just does not work right. My earlier post was marked as the answer.

    Allan Horwitz
  • Re: Img Source proglem

    04-28-2008, 10:16 AM
    • Loading...
    • danishjee
    • Joined on 10-31-2007, 11:06 AM
    • Pakistani
    • Posts 59

    here is my code from my MASTER PAGE

    when i use this below code on my master page ....its perfect

    <img runat="server" src="imgs/2.png" />

     but when i use this below code for back gournd image on my master page so i can not see this back ground image on my sub Folder pages.I did not paste full code just need to consuntrate on back ground image

    <body bgcolor="#000000" style="background-image: url('imgs/background.png'); background-repeat: repeat-x;">

     

    <form id="form1" runat="server">

    <table align="center" class="style10">

    <tr>

    <td class="style11"

    style="background-image: url('imgs/topbg.png'); background-repeat: no-repeat; background-position: center top">

    <table align="center" cellpadding="0" cellspacing="0" class="style12">

    <tr>

    <td class="style13">

    </td>

    ==============here is another code example which is not working properly=================

    <table align="center" class="style17" runat="server"

    style="background-image: url('~/imgs/2.png'); background-repeat: no-repeat; background-position: center center">

    </table>

  • Re: Img Source proglem

    04-28-2008, 5:45 PM
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 6,852
    • Moderator
      TrustedFriends-MVPs

    ok - that markup helps.

    first, the ~/ syntax is only for properties of server controls so you can't use that syntax nested inside of a style tag url().

    My personal preference is to avoid putting the styles directly into the markup like this.  instead, i would put those styles into a css sheet as class selectors, then i would assign the class selectors to the elements I'm trying to style.  In addition to making your markup slightly smaller (no more embedded styles)  this will also help you with your image paths.

    when you define a url in a css sheet (like MyStyles.css), the image path is relative to where the css sheet is stored in your folder structure and not to which folder the aspx page is rendering from. so if the css sheet were in the root of your app and you had a subfolder for your images named imgs, then in the css sheet, you can set your urls like this:

     background-image: url('imgs/2.png');

    Since this image path is relative to where the css sheet is stored it will work whether the web page is pulled from your site root or from a subfolder.

    The one path that you will now need to carefully deal with is the path to the stylesheet itself.  Since the masterpage can be pulled from any page at any folder level, your stylesheet link needs to be able to deal with that.  fortunately, that root relative ~/ syntax will work just fine for the css link tag.

    in your masterpage head section you can add that css link like this:

    <link runat="server" 
          id="csslnk1"
          href="~/MyStyles.css"
          rel="stylesheet" type="text/css" />

    because the link is runat=server and were setting the href to ~/MyStyles.css, all your pages will get a proper link to the css stylesheet stored in the root of your app regardless of which subfolder your page is being pulled from.

    since you defined any background-image urls inside the actual css stylesheet as being relative to the root of your app (where the stylesheet is stored) then all images will be found - again regardless of which subfolder your page is being pulled from.

    hope this helps

    Mike Banavige
    ~~~~~~~~~~~~
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Img Source proglem

    05-05-2008, 9:52 AM
    • Loading...
    • krishnav
    • Joined on 05-01-2008, 9:45 AM
    • Vijayawada
    • Posts 49

    probelm with the folders.. where u stored ur master page n aspx pages..

     <img alt="" src="imgs/4.gif" style="width: 794px; height: 41px"/> is it working for master page... if so

    master page is not in another folder it is in root folder..n images are in imgs folder...

    if aspx pages r also in root dir it will work.. or check the aspx files path.. if they r in another folder then try like this

     <img alt="" src="../imgs/4.gif" style="width: 794px; height: 41px"/>

    i think it will work..

     

  • Re: Img Source proglem

    05-07-2008, 2:39 AM