Using the ImageUrl property of the HyperLink control

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Jan 29, 2009.

  1. I have several HyperLink controls on my site in which I use the ImageUrl
    property to display them as an image. This generates something like the
    following:

    <a><img/></a>

    I would like to specify the height and width of the image, but if I use the
    HyperLink's Height and Width properties, something like the following is
    generated:

    <a style="display:inline-block;height:100px;width:100px;"><img/></a>

    My basic problem here is that there is no way to add style to the image.
    Yes, I know that I could make the HyperLink and image separate controls or
    create a CSS class that uses a child selector. But we all know that it is
    good practice to set the width and height of images, so why did they give
    the HyperLink an ImageUrl property if you can't specify it's width and
    height? In my opinion, the HyperLink is very poorly designed when it comes
    to creating graphical hyperlinks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Jan 29, 2009
    #1
    1. Advertising

  2. Nathan Sokalski

    iduditz Guest

    Its probably easier to just use the img itself i.e.
    <a href="bla"><img src="bla" width="64" height="64"></a>

    "Nathan Sokalski" wrote:

    > I have several HyperLink controls on my site in which I use the ImageUrl
    > property to display them as an image. This generates something like the
    > following:
    >
    > <a><img/></a>
    >
    > I would like to specify the height and width of the image, but if I use the
    > HyperLink's Height and Width properties, something like the following is
    > generated:
    >
    > <a style="display:inline-block;height:100px;width:100px;"><img/></a>
    >
    > My basic problem here is that there is no way to add style to the image.
    > Yes, I know that I could make the HyperLink and image separate controls or
    > create a CSS class that uses a child selector. But we all know that it is
    > good practice to set the width and height of images, so why did they give
    > the HyperLink an ImageUrl property if you can't specify it's width and
    > height? In my opinion, the HyperLink is very poorly designed when it comes
    > to creating graphical hyperlinks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    >
    >
     
    iduditz, Jan 29, 2009
    #2
    1. Advertising

  3. Nathan Sokalski

    Patrik Guest

    Yep you are right. The ImageUrl is pretty useless if you want to
    control the attributes of the image.
    But the control also provides you with the ability to add subcontrols.
    For example:

    Image img = new Image();
    img.ImageUrl = "picture.jpg";
    img.Width = new Unit(150, UnitType.Pixel);
    img.Height = new Unit(150, UnitType.Pixel);

    MyHyperLinkControl.Controls.Add(img);

    That would probably work pretty much the way you want, and you can
    access all attributes of the image.

    ///Patrik

    On 29 Jan, 03:24, "Nathan Sokalski" <> wrote:
    > I have several HyperLink controls on my site in which I use the ImageUrl
    > property to display them as an image. This generates something like the
    > following:
    >
    > <a><img/></a>
    >
    > I would like to specify the height and width of the image, but if I use the
    > HyperLink's Height and Width properties, something like the following is
    > generated:
    >
    > <a style="display:inline-block;height:100px;width:100px;"><img/></a>
    >
    > My basic problem here is that there is no way to add style to the image.
    > Yes, I know that I could make the HyperLink and image separate controls or
    > create a CSS class that uses a child selector. But we all know that it is
    > good practice to set the width and height of images, so why did they give
    > the HyperLink an ImageUrl property if you can't specify it's width and
    > height? In my opinion, the HyperLink is very poorly designed when it comes
    > to creating graphical hyperlinks.
    > --
    > Nathan Sokalski
    > ://www.nathansokalski.com/
     
    Patrik, Jan 29, 2009
    #3
  4. You are correct in your solution, but I was looking for a way to do this
    declaratively using only the HyperLink control. Please don't bother to tell
    me some other combination of tags/controls that will produce what I
    mentioned, because I know how to do it that way. Basically all I am saying
    in this post is that there are certain things that a control should give you
    access to, and in my opinion the HyperLink does not do that.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Patrik" <> wrote in message
    news:...
    > Yep you are right. The ImageUrl is pretty useless if you want to
    > control the attributes of the image.
    > But the control also provides you with the ability to add subcontrols.
    > For example:
    >
    > Image img = new Image();
    > img.ImageUrl = "picture.jpg";
    > img.Width = new Unit(150, UnitType.Pixel);
    > img.Height = new Unit(150, UnitType.Pixel);
    >
    > MyHyperLinkControl.Controls.Add(img);
    >
    > That would probably work pretty much the way you want, and you can
    > access all attributes of the image.
    >
    > ///Patrik
    >
    > On 29 Jan, 03:24, "Nathan Sokalski" <> wrote:
    >> I have several HyperLink controls on my site in which I use the ImageUrl
    >> property to display them as an image. This generates something like the
    >> following:
    >>
    >> <a><img/></a>
    >>
    >> I would like to specify the height and width of the image, but if I use
    >> the
    >> HyperLink's Height and Width properties, something like the following is
    >> generated:
    >>
    >> <a style="display:inline-block;height:100px;width:100px;"><img/></a>
    >>
    >> My basic problem here is that there is no way to add style to the image.
    >> Yes, I know that I could make the HyperLink and image separate controls
    >> or
    >> create a CSS class that uses a child selector. But we all know that it is
    >> good practice to set the width and height of images, so why did they give
    >> the HyperLink an ImageUrl property if you can't specify it's width and
    >> height? In my opinion, the HyperLink is very poorly designed when it
    >> comes
    >> to creating graphical hyperlinks.
    >> --
    >> Nathan Sokalski
    >> ://www.nathansokalski.com/

    >
     
    Nathan Sokalski, Jan 30, 2009
    #4
  5. Nathan Sokalski

    Brickbat Guest

    I don't understand how this glaring omission hasn't been fixed by Microsoft.
    Don't they care that developers see stuff like this and think 'PHP please' or
    'JSP whatever'. I get so frustrated by this kind of crap - they need to fire
    all the suits with their marketing garbage and hire a few more developers.

    "Nathan Sokalski" wrote:

    > You are correct in your solution, but I was looking for a way to do this
    > declaratively using only the HyperLink control. Please don't bother to tell
    > me some other combination of tags/controls that will produce what I
    > mentioned, because I know how to do it that way. Basically all I am saying
    > in this post is that there are certain things that a control should give you
    > access to, and in my opinion the HyperLink does not do that.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Patrik" <> wrote in message
    > news:...
    > > Yep you are right. The ImageUrl is pretty useless if you want to
    > > control the attributes of the image.
    > > But the control also provides you with the ability to add subcontrols.
    > > For example:
    > >
    > > Image img = new Image();
    > > img.ImageUrl = "picture.jpg";
    > > img.Width = new Unit(150, UnitType.Pixel);
    > > img.Height = new Unit(150, UnitType.Pixel);
    > >
    > > MyHyperLinkControl.Controls.Add(img);
    > >
    > > That would probably work pretty much the way you want, and you can
    > > access all attributes of the image.
    > >
    > > ///Patrik
    > >
    > > On 29 Jan, 03:24, "Nathan Sokalski" <> wrote:
    > >> I have several HyperLink controls on my site in which I use the ImageUrl
    > >> property to display them as an image. This generates something like the
    > >> following:
    > >>
    > >> <a><img/></a>
    > >>
    > >> I would like to specify the height and width of the image, but if I use
    > >> the
    > >> HyperLink's Height and Width properties, something like the following is
    > >> generated:
    > >>
    > >> <a style="display:inline-block;height:100px;width:100px;"><img/></a>
    > >>
    > >> My basic problem here is that there is no way to add style to the image.
    > >> Yes, I know that I could make the HyperLink and image separate controls
    > >> or
    > >> create a CSS class that uses a child selector. But we all know that it is
    > >> good practice to set the width and height of images, so why did they give
    > >> the HyperLink an ImageUrl property if you can't specify it's width and
    > >> height? In my opinion, the HyperLink is very poorly designed when it
    > >> comes
    > >> to creating graphical hyperlinks.
    > >> --
    > >> Nathan Sokalski
    > >> ://www.nathansokalski.com/

    > >

    >
    >
    >
     
    Brickbat, Apr 18, 2009
    #5
    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. Nathan Sokalski
    Replies:
    4
    Views:
    10,681
    nazanim2000
    Jun 2, 2010
  2. Aidy
    Replies:
    0
    Views:
    377
  3. Nathan Sokalski
    Replies:
    4
    Views:
    956
    Brickbat
    Apr 18, 2009
  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:
    182
    Arthur Dent
    Oct 10, 2005
  5. injy
    Replies:
    0
    Views:
    231
Loading...

Share This Page