Thursday, March 22, 2012

set image url programmatically for image control

I have a print page that uses an image control to display an image that is saved in a directory that is dynamically created upon a session start. I have the path readily available for the image control...but I am failing to get the image to display in the image control...

what is the syntax to properly set the url for an image control programmatically in the code behind?

the control is named printImage

thanks in advance

Eric

printImage.src=


printImage.ImageUrl = "your URL";

simple as that.


I am not getting the .src in intellisense for the control - is there a namespace/directive that I am missing?


ekeefauver:

I am not getting the .src in intellisense for the control - is there a namespace/directive that I am missing?

Nope, it's just, that property is called "ImageUrl" and not "src".


doesn't seem to work for me...do I somehow need to refresh the control after setting the URL to the image?

the path to the image is: C:\Documents and Settings\dekeefau\My Documents\Visual Studio 2005\WebSites\CMAT_FINAL\sessions\sd_ewwewtjwy23b5vnrmxm1mffz\print\theimage.bmp

which is stored in a string variable


No, there is no need to refresh the control. Perhaps the path you are using is not valid? Try using Server.MapPath() function with the relative path to the image in question.

Example:

Image is in the /Images subfolder of the application and its name is MyImage.gif

Then the code to display this image would be:

printImage.ImageUrl = Server.MapPath("~/Images/MyImage.gif");

0 comments:

Post a Comment