Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Programmatically add a url to an image

Posted on 2008-06-12
2
Medium Priority
?
458 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

705 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