Solved

Programmatically add a url to an image

Posted on 2008-06-12
2
441 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 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

11 Experts available now in Live!

Get 1:1 Help Now