简体   繁体   中英

cannot set image on code behind

I´m creating a result pool, where depending on the query string, the page loads the image. I have the following object

<li class="labelForm"><asp:Image ID="imgImagen" runat="server" /></li>

on the page_load event i got:

string path = res == "OK" ? (Server.MapPath("~/Images/Results/OK/")) : (Server.MapPath("~/Images/Results/NO/"));

path = App_Code.FilePicker.FilePicker(path);
imgImagen.ImageUrl = path;

The image route is a valid one. I tested it on the browser and the explorer

D:\\Proyectos Web Forms\\MyPage\\MyPage\\Images\\Results\\OK\\thumbsUp2.jpg

Since the code is running on the Page_Load event (way before render event), it shouldn't be the problem, and the file route is valid. However, the browser displays a little icon of empty image.

What could I be missing?

when i add a local file to a url like that it usually converts it automaticaly for me to: from: C:/Users/Carlos/Desktop/options.gif to file:///C:/Users/Carlos/Desktop/options.gif

what happens if you take the rendered path (from the "view source") and paste it directly into explorer? i've seen IE9 put up a message saying it "blocked content" and i have to click "allow content" for it to work. Maybe that's what's happening?

---- * edit * oh, and i also noticed you didn't specify a filename, such as helloworld.gif :)

I was using absolute routes, instead of a relative route. Instead of this:
"D:\\\\Proyectos Web Forms\\\\MyPage\\\\MyPage\\\\Images\\\\Results\\\\OK\\\\thumbsUp2.jpg"

Should be this:
"~/Images/Results/OK/thumbsUp2.jpg"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM