We help IT Professionals succeed at work.

Make an image hyperlink

dizzycat
dizzycat asked
on
Hi guys
Using visual web developer 2008 express, how can i make an image or an image button into a hyperlink to navigate to another of my websites pages, i have looked at all the controls in the toolbox and all of the properties of each control but cannot achieve this.
Comment
Watch Question

Chinmay PatelChief Technology Ninja
Distinguished Expert 2019

Commented:
Hi dizzycat,
You can wrape your image tag like this
<a href="target site"><img src="myimg.jpg"/></a>
Regards,
Chinmay


If you are using the designer, place your Hyperlink Control and set NavigateUrl to whatever you want.
Set the following as Text of the Hyperlink Control:

<img src="http://example.com/path_to_your_image.jpg" />

which results in the following source code:

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">
     <img src="http://example.com/path_to_your_image.jpg" alt=""  />
</asp:HyperLink>
   

By the way... if you want to use an ImageButton (which I wouldn't recommend for SEO Reasons) you'd place your ImageButton and put the following code into the OnClick Event:

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
   Response.Redirect("http://example.com");
}

But please note, that the link target won't be visible to anyone until they have clicked the button and are being redirected to that page.

Author

Commented:
Great!
Thanks for your help.