473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

setting ImageUrl for images through code not working

Dear world,

I have an IMAGE control placed on my .aspx page with its ImageUrl
property not set.

In my code, i am setting it equal to something using the following
statement

img.ImageUrl = Server.MapPath ("usedIcons/AssignAccess/" +
reader["sImage"].ToString ());

where reader as the name implies is a DataReader object reading a value
from the database.

The funny part is, when I run the code in LOCALHOST mode, it works
perfectly. But it was an embarassing experience for me, when I finally
deployed on server and asked my client to try from their remote client
machine. THE IMAGE DID NOT LOAD. All such images had the usual "X" on
them.

Why does it work on LOCALHOST, but not when viewing from a remote
client?

My doubts in case it helps you to help me:
1. Is Server.MapPath the right way to do it?
2. Is there any place in the document where this code should be kept?
3. I will be shocked if the answer to this one is "yes". "IS THE
BROWSWER LOOKING FOR THE IMAGE ON THE CLIENT MACHINE RATHER THAN ON
SERVER?"

Thanks a lot...

Michelle Stone

Nov 19 '05 #1
2 2418
YES, the client machine is looking for the file locally, not on your server.
Server.MapPath is for working with local paths.
In this case you want a URL that points to the image, not a local path.

To verify this you can view the HTML that is sent to the browser.
(Right click on IE web page and choose View Source.)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
<mi********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Dear world,

I have an IMAGE control placed on my .aspx page with its ImageUrl
property not set.

In my code, i am setting it equal to something using the following
statement

img.ImageUrl = Server.MapPath ("usedIcons/AssignAccess/" +
reader["sImage"].ToString ());

where reader as the name implies is a DataReader object reading a value
from the database.

The funny part is, when I run the code in LOCALHOST mode, it works
perfectly. But it was an embarassing experience for me, when I finally
deployed on server and asked my client to try from their remote client
machine. THE IMAGE DID NOT LOAD. All such images had the usual "X" on
them.

Why does it work on LOCALHOST, but not when viewing from a remote
client?

My doubts in case it helps you to help me:
1. Is Server.MapPath the right way to do it?
2. Is there any place in the document where this code should be kept?
3. I will be shocked if the answer to this one is "yes". "IS THE
BROWSWER LOOKING FOR THE IMAGE ON THE CLIENT MACHINE RATHER THAN ON
SERVER?"

Thanks a lot...

Michelle Stone

Nov 19 '05 #2
When you view the images from the remote host right click on the
missing image (where the "X" is) and select properties. This will tell
you where the path is getting resolved to.... From this information
you will probably see the error....

More importantly you should not be using MapPath at all to set the
ImageUrl property. MapPath is used to find a Physical Path on the hard
drive for a file... That means the path is resolving to something like
c:\inetpub\wwwroot\myweb\images.....etc.... not good!

Just set the ImageUrl like:
img.ImageUrl = "usedIcons/AssignAccess" + reader["sImage"].ToString ());

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Joe | last post by:
I have a function that changes an image when the user clicks a button (this works fine). There's another button that is used to transfer to another page an pass the selected image as a querystring....
1
by: tshad | last post by:
Is there some reason why the Hyperlink in a DataGrid will not show an image? I have a datagrid with the following: <asp:TemplateColumn visible="false" HeaderText="Skills"> <itemtemplate>...
1
by: Nathan Sokalski | last post by:
I am using the ImageUrl property of the Hyperlink control to create a graphical Hyperlink. However, I want to change the size of the image I am using, but the generated HTML places the width/height...
1
by: Nick Gilbert | last post by:
Hi, I have just migrated my .NET 1.1 site to .NET 2.0. Most things are now working except that a lot of my images aren't displaying if they referenced the image path using ~. eg: ...
4
by: Ben | last post by:
Hi, I'm using images in my menu control. I have my menu setup based on this example: http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.menuitembinding.imageurlfield(VS.80).aspx ...
0
by: Jeff | last post by:
Hey ASP.NET 2.0 I'm working on a website which I want the menu control to have images to left for the text in the menuitem... So far I've read that this can be done by providing the ImageUrl...
3
by: Ganesh | last post by:
Hi There I've assigned the Imageurl on ImageButton in design time like this http://localhost/aspnetsbs_cs/SimpleTest/WebForm4.aspx?image=images/one.jpg&size=100 but when i try from on run...
1
by: BillGatesFan | last post by:
Is there a way to change to swapimages for an imagemap in asp.net upon postback on the server? Thanks!
5
by: OK | last post by:
I am using an image control to display some images within a virtual map (ImagesRoot in IIS) outside of the web root in my vb asp.net application. How should I code the imageurl property to have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.