开发者

why can't I programmatically set the imageurl on an Image control?

I have an ASP.NET 2010 app and am trying something very simple. I use Image control through out and basically wanted to say, before I assign an image to it (from a class) look for the image; if it's not there, use the default no_image jpeg I have. I have verified the image is there ad nauseam. If I set the property in the IDE to point to this image, it'll display. However, if I set it programmatically, even if I hard-code the path programmatically, it doesn't show.

Forgettign about getting the proper path and all that, (of which Ive tried several things) I can;t even hard code the relative path. Here I copied & pasted the relative path from the properties window...

Image1.ImageUrl = "~/UploadedPic开发者_StackOverflow中文版tures/Users/no_profile_picture.jpg" 

This doesn't work. It translates into src="../../UploadedPictures/Users/no_profile_picture.jpg" which is correct but the image doesn't display.

If I hardcode the absolute path it doesn't work either...

Image1.ImageUrl = "C:\Inetpub\wwwroot\myApp\UploadedPictures\Users\no_profile_picture.jpg"


You have to use a virtual path. Try adding ~ before your path.

Image1.ImageUrl = "~/UploadedPictures/Users/no_profile_picture.jpg"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜