how to change an image url at runtime

  • Thread starter Thread starter Mark Kamoski
  • Start date Start date
M

Mark Kamoski

How can one change an image url at runtime?

(Note, the image exists in a user control.)

This is the image tag on the ascx...

<asp:image id="TopBanner" runat="server"></asp:image>

....but I cannot get this to change from the code behind of a page that
hosts the user control.

Any ideas?

Thanks.
 
....argghhh...

....still cannot figure this out...

....any help is appreciated...



Ugg.

Is there another way to do this without using Response.Write?

Why doesn't something like this work?

This code is in the code-behind for the user control for the Nav, which
SHOULD swap the a top banner image.

Why doesn't it work?

What do you think?

(Note-- I don't see where a Response.Write will help in this case.

(I suspect this has something to do with postback, the event cycle of the
host page, the event cycle of the user control, or something related to
these-- but, I don't know exactly where.)

//This is an image button event handler that exists in the user control.
//The image button exists on the user control.
//
private void ShowFeedback_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
ShowBanner("Feedback");
Response.Redirect("Feedback.aspx?Nav=Feedback");
}

//This is the helper method that exists in the user control.
//
private void ShowBanner(string NavValue)
{
TopBanner.ImageUrl = "Images/BannerTop" + NavValue + ".gif";
}




Try:

Response.Write("<script>TopBanner.src =
\"http://www.site.com/image.gif\";</script>");

Jon
 
Back
Top