Changing the width/height when using Hyperlink.ImageUrl

  • Thread starter Nathan Sokalski
  • Start date
N

Nathan Sokalski

I am using the ImageUrl property of the Hyperlink control to create a
graphical Hyperlink. However, I want to change the size of the image I am
using, but the generated HTML places the width/height properties in the
anchor tag rather than the image tag. Obviously I could write code to
generate the anchor/image tags myself, but when a control as nice as the
Hyperlink already exists I want to know if there is any kind of workaround
that will let me use the Hyperlink control. Any ideas?
 
A

Arthur Dent

Hi Nathan,

Ive found this same problem, in an online catalog where there was a
thumbnail of product images which should be hyperlinks to the individual
product pages.
There were three ways i've gotten around this, the first is to the text
property of your hypelink control as an image (kinda kludgey):
lnkImage.Text = "<img src='" & ResolveUrl("~/images/someimage.gif") & "'
width=150>"

The next is to directly handle the image control in the hyperlink, which i
only did once or twice, but got it working, something kind of like (not 100%
sure about the sytanx here):
lnkImage.ImageUrl = ResolveUrl("~/images/someimage.gif")
Dim img As Image = lnkImage.Controls(0)
img.Width = New Unit(150, Pixels)

The way i usually do this though is to edit the HTML code and do something
like the following:

<asp:hyperlink id=lnkImage runat=server
navigateurl="~/index.aspx?m=f&id=123">
<asp:image id=imgImage runat=server imageurl="~/images/someimage.gif"
width="150px"></asp:image>
</asp:hyperlink>

Hope this helps, its all workarounds, but they work. You could always
subclass the hyperlink control and override its render event, but these are
easier.

Cheers,
- Arthur Dent.
 
Joined
Feb 9, 2010
Messages
1
Reaction score
0
My favorite solution is to use css

<style>.thumb80 img {width:80px}</style>
...
<asp:hyperlink CssClass="thumb80" id=lnkImage runat=server
navigateurl="~/index.aspx?m=f&id=123" imageurl="~/images/someimage.gif"
/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top