Changing the width/height when using Hyperlink.ImageUrl

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Oct 8, 2005.

  1. 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?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Oct 8, 2005
    #1
    1. Advertising

  2. Nathan Sokalski

    Arthur Dent Guest

    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.


    "Nathan Sokalski" <> wrote in message
    news:e$...
    >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?
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    Arthur Dent, Oct 10, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian Pické
    Replies:
    0
    Views:
    406
    Christian Pické
    Nov 6, 2003
  2. Nathan Sokalski
    Replies:
    4
    Views:
    10,654
    nazanim2000
    Jun 2, 2010
  3. bruticus
    Replies:
    0
    Views:
    445
    bruticus
    Oct 5, 2007
  4. Nathan Sokalski

    Changing the width/height when using Hyperlink.ImageUrl

    Nathan Sokalski, Oct 8, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    179
    Arthur Dent
    Oct 10, 2005
  5. lightman

    Hyperlink imageurl width/height ignored?

    lightman, Oct 6, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    196
    lightman
    Oct 6, 2003
Loading...

Share This Page