IMG tag in page HTML

Sep 27, 2010 at 1:08 AM

I have an image in a subdirectory of my site /pics and I want to display an image in the HTML for a page using the IMG tag. Is this the right way. I cannot get the picture to display no matter how I format the src element for the IMG tag except by putting the full URL.

 

Any thoughts?

 --- x

Sep 27, 2010 at 3:55 AM

You can use "~" to represent the root of the web application, if you add runat="server" to your image link.  So, if your image is called "my_cool_image.png" and is in the root of your application, you'd have something like...

<img src="~/my_cool_image.png" runat="server" alt="No image for you" />

There are other ways to skin the cat, but this is probably the quickest.

Sep 27, 2010 at 4:32 AM

danielsummers,

 Thanks for the reply. I tried various forms of what you suggested. The following finally worked but only on IE:

<img src="pics/DAVE4Side2.jpg"  />

If I use the "~" character, I get strange results. However the above produced the following CORRECT URL for the image in IE:

http://localhost/colokenpo/pics/DAVE4Side2.jpg

But in Firefox, I get the following INCORRECT url:

http://localhost/colokenpo/page/pics/DAVE4Side2.jpg

Very strange.

About the only thing I can do is to publish the images to the real target directory where I am going to deploy the application and to use the entire url. this is a bummer however, because I'd really just like to test this locally and not have to have files scattered. If you have any other suggestions I'd greatly appreciate it.

Thanks!

 --- x

 

Coordinator
Sep 27, 2010 at 3:14 PM

The "~" only works with runat="server", as Daniel mentioned.

Sep 27, 2010 at 4:55 PM

How about this, I'm not sure if this is what you are asking but I had a similar issue and this worked for me.

 

<img src='<%= ResolveUrl("images/example.jpg") %>' alt="" />