Solved

Programmatically add a url to an image

Posted on 2008-06-12
2
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

628 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