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

05-16-2007, 05:52 PM

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";

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

Any reply would be greatly appreciated!


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;

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.


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.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum