tags:

views:

17

answers:

3

I have used the below code to display image on top of the page. For condition1

div1.Visible = true;
div2.Visible = false;

For condition2,

div1.Visible = false;
div2.Visible = true;

and the code in the aspx page is like this.

<div id="div1" runat="server" style="padding-left: 110px;">
  <img src="~/images/Package-Summary.gif" alt="Package Summary" />          
</div>

<div id="div2" runat="server" style="padding-left: 110px;">
  <img src="~/images/Process-Billing.gif" alt="Process Billing" />          
</div>

Here it doesnot show me the image, instead shows an error box in that part!! What might be the reason!!!

+1  A: 

I think you need a relative path to the image:

<img src="../images/Process-Billing.gif" alt="Process Billing" />
Matthew Jones
If the image couldn't be found the alt text would just display not an error.
Ash Burlaczenko
I am Sorry.. Thats what i meant!! alt text is displayed! Where is the problem at??
Ram
@Ash I don't think that is entirely correct. IE6 displays both the image-not-found image and the alt text, and my Chrome displays only the image-not-found icon.
Matthew Jones
On my localhost(IE), it shows alt text and an error icon i guess(box with red X inside)
Ram
@Ram you need to specify the path in a relative manner. If the page with the `<img>` element is located at Pages/SpecialPages/pagename.aspx, for example, the relative path to the image might be ../../images/Process-Billing.gif
Matthew Jones
Matthew, I checked that buddy! But everything looks perfect here, i am so helpless!
Ram
@Ram Two things: one, you are sure the image exists where you think it does, right? Two: are you using Visual Studio? If you are, if you delete and then retype the `src=`, VS should give you a list of items in the current folder. If you scroll all the way down you should see `Pick URL...` and can use that to get the correct image path.
Matthew Jones
Yes Matthew, i did that. Unfortunately, it is the same old path!! :(
Ram
A: 

Your images are using server-side paths, but they're not server-side controls. The divs surrounding them are server-side controls, which doesn't affect the images. Either convert the image controls to server-side or convert the paths to something the client can request (relative paths, ideally).

David
A: 

Actually your images are not picking the right path as you are using server path at client side. If you want to use root-relative path you should use server side Image control to assign path.

You can use an Image server control and can just change its source but I do not know what you exactly want. But on client you use relative path not root-relative path. For root-relative path you have to use server image control.

see the article

ASP.NET Web Project Paths

so it should be

<div id="div1" runat="server" style="padding-left: 110px;">
  <img src="../images/Package-Summary.gif" alt="Package Summary" />          
</div>

<div id="div2" runat="server" style="padding-left: 110px;">
  <img src="../images/Process-Billing.gif" alt="Process Billing" />          
</div>

or where ever your image directory is you can go back to your image directory by just adding another "../" before path to go back to image directory.

Azhar