PDA

View Full Version : Set an image source dynamically from a variable or QueryString



QuickFix
05-16-2007, 05:52 PM
Hi,

I have a simple request. How do I set the source of an image in an ASP page using a variable? Example:

<script runat="server">
protected void Page_Load(Object Source, EventArgs E)
{
String Image = "http://www.codingforums.com/img/logo.gif";
}
</script>

<asp:Image ID="Image1" runat="server" ImageUrl = (Image Variable) />

Any reply would be greatly appreciated!

QF

glenngv
05-16-2007, 06:59 PM
This should be in ASP.NET forums. I'm not a .NET developer but I'll make an educated guess.


String Image = "http://www.codingforums.com/img/logo.gif";
Image1.ImageUrl = Image;

QuickFix
05-16-2007, 07:28 PM
Hi Glenn,

I believe that's the correct approach. It just doesn't appear to work for me...

In my ASP page I have this code:

<asp:image runat ="server" ID = "Image1" />

And in the Code Behind page, I have the code you listed.

M

glenngv
05-17-2007, 09:43 PM
Is there any error? You may want to ask the mods to move this thread to ASP.NET Forum to get more useful answers.