Hi,
This seem like a fairly basic thing to do, but I just can not get it right!?
I want to allow the visitors to my web site the option to decide if they want to see images at a lower resolution and thus increase the speed of my web site. To do this, I have a 3 different directories with the same image in it, just the size (800x600, 640x480) of the images differ in each directory. Depending on the users preference, I want to show the picture, but change the directory to appropriate directory in the page_load. My code looks something like this:
In the web form:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:Image ID="Image1" runat="server" ImageUrl="<%=graphicsDir %>" />
</asp:Content>
In the code behind:
string graphicsDir = "~/images/"; // variable with path to the directory where the graphics are
if (width = 640)
{
//which graphics directory should be used?
graphicsDir = graphicsDir + "640/myPicture.jpg";
}
if (width = 800)
{
//which graphics directory should be used?
graphicsDir = graphicsDir + "800/myPicture.jpg";
}
I do not get an error, but the picture does not show at all. If I "right click" on the empty place holder, then in the picture properties there are no information regarding the picture - so the variable in the HTML was not updated:
Not Available
Protocol: Not Available
Type: Not Available
Address(URL): Not Available
Size: Not Available
But, if I display the value of "graphicsDir" in a Label, then it shows the correct path, for example: "~/images/800/arch.jpg"
How can I solve this, or is it not possible to do this with a asp:image?