Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2011, 05:38 PM
Authorized User
 
Join Date: Feb 2011
Posts: 21
Thanks: 9
Thanked 0 Times in 0 Posts
Default Can asp:image work as href or...

Hi,

Can a <asp:image be used as an href or to open Url's?

<p><asp:Image id="Image1" ImageUrl="~/Img/Img1.jpg" runat="server"/></p>
 
Old February 12th, 2011, 05:54 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Jim,

No, the Image control doesn't support that. However, you can turn things around and assign an image to a HyperLink or ImageButton:

Code:
 
<asp:HyperLink ID="HyperLink1" runat="server" ImageUrl="~/Img/Img1.jpg" />
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Img/Img1.jpg" />
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
JimP (February 12th, 2011)
 
Old February 12th, 2011, 06:41 PM
Authorized User
 
Join Date: Feb 2011
Posts: 21
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Thank you, that looks great. But, it did not work in my code...
I get a: System.FormatException: Input string was invalid format
when I hit Button1

Can you take a look?


<script runat="server">
Sub submit(Sender As Object, e As EventArgs)
if red.Checked then
Hyperlink1.ImageUrl = "~/Img/Img1.jpg" And
Hyperlink1.NavigateUrl = "http://www.vg.no"
elseIf green.Checked then
Hyperlink1.ImageUrl = "~/Img/Img2.jpg" And
Hyperlink1.NavigateUrl = "http://www.dn.no"
elseIf blue.Checked then
Hyperlink1.ImageUrl = "~/Img/Img3.jpg"
end if
End Sub
</script>

<html>
<body>

<form id="Form1" runat="server">
Select:
<br />
<asp:RadioButton id="red" Text="Red" Checked="True"
GroupName="colors" runat="server"/>
<br />
<asp:RadioButton id="green" Text="Green"
GroupName="colors" runat="server"/>
<br />
<asp:RadioButton id="blue" Text="Blue"
GroupName="colors" runat="server"/>
<br />
<asp:Button ID="Button1" text="Submit" OnClick="submit" runat="server"/>
<p><asp:HyperLink id="Hyperlink1" runat="server" ImageUrl="~/Img/Img1.jpg" NavigateUrl= /></p>
&nbsp;<p><asp:Label id="Label1" runat="server"/></p>
</form>


Thanks!
JimP


Salute
www.Wimp.no
www.Spotify.com
Asia
 
Old February 12th, 2011, 06:49 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Him Jim,

The And keywords shouldn't be there. Each assignment should simply be placed on its own line.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
JimP (February 12th, 2011)
 
Old February 12th, 2011, 07:17 PM
Authorized User
 
Join Date: Feb 2011
Posts: 21
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Hi Imar!

It worked!!! Thank you!!!

I smile from the moon to the sun, the sky lighten up the moment I phushed the butten:)

Thank you again Imar!:)



Salute
www.Wimp.no
www.Spotify.com
Hot band= Asia & Boston






Yes it's saturday and I have something in the glas:)
Weekend whitout wife and kids:)
I call it Webweekend:)





Similar Threads
Thread Thread Starter Forum Replies Last Post
set image on <asp:Image> stored in DataBase myself.panku ASP.NET 2.0 Professional 1 August 11th, 2008 10:41 AM
Chapter 8, href and HRef (p. 285) roman BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 June 16th, 2008 10:40 AM
Work with Image cli PHP How-To 1 July 19th, 2005 06:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.