user993354
user993354

Reputation: 45

Image1.ImageUrl = .. does not change the picture on the WEB page

I work on WEB app on C# VS 2010. I have WEB form with the button and Image control. I draw my own image in bitmap.

        bitmap.Save(Server.MapPath("pic1.jpg"), ImageFormat.Jpeg);
        Image1.ImageUrl = Server.MapPath("pic1.jpg");

The problem is that the above code does not change the picture in "Image1"

I also tryed as follows: bitmap.Save(Response.OutputStream,ImageFormat.Jpeg); It works. I see my image. But I don't see any other controls on the WEB page: no my buttons, labels, etc. Only the image on the page.

Perhaps I have to bind my own image in bitmap to Image1 somehow different?

Thanks.

Upvotes: 0

Views: 3472

Answers (1)

Wiktor Zychla
Wiktor Zychla

Reputation: 48279

The Server.MapPath returns a file name. On the other hand, Image.ImageUrl expects a valid url.

How do you expect a file name will magically act as an url?

You'd rather want something like

Image1.ImageUrl = this.ResolveUrl( "pic1.jpg" );

or something similar which resolves paths to navigable uris.

Upvotes: 2

Related Questions