Solved

Programmatically add a url to an image

Posted on 2008-06-12
2
427 Views
Last Modified: 2013-12-17
Greetings all

I have an image (asp:Image) on my page. When the user clicks on it I would like them to be redircted elsewhere (preferably in another window).

1.  How do I programmatically add a url to the image?
2.  If there is no url available, do I disable the image, or is it ok to just leave it like that, knowing that clicking
    will  do nothing?


In advance, thanks!

    allanmark
0
Comment
Question by:allanmark
2 Comments
 
LVL 22

Accepted Solution

by:
prairiedog earned 250 total points
ID: 21773040
The ASP.NET Image control does not have a URL property (I mean something like NavigateUrl property in HyperLink control), though it has an ImageUrl property. So you need to accomplish this with JavaScript. Here is how to dynamically add a redirect url to the Image control so that when user clicks on the image, they will be redirected:

string url = getURL(); // change this to your function that gets the redirected url
if (url != "")
{
    this.Image1.Attribute.Add("onclick", "javascript:document.location.href='" + url + "'");
}

You have to run the above code in your Page_Load event handler to make it work.
0
 

Author Closing Comment

by:allanmark
ID: 31466703
ThankYou!! Sorry 4 taking so long to close!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now