Solved

Programmatically add a url to an image

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

809 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