Image Server Control's Style/Border

Discussion in 'ASP .Net Web Controls' started by Matt Sollars, Mar 29, 2006.

  1. Matt Sollars

    Matt Sollars Guest

    Hello.

    Has anyone else noticed that the Image server control emits a style
    attribute for a 0px border by default? If I drop an Image control on a
    form and set nothing but the ImageUrl property, it is rendered as the
    following:

    <img id="Image1" src="Blue%20hills.jpg" style="border-width:0px;" />

    This is just not good when I want to specify a CSS class for the image
    that uses a border. Again, if I add a value to the CssClass property to
    my image that specifies a border, it is still rendered as follows:

    <img id="Image1" class="Bordered" src="Blue%20hills.jpg"
    style="border-width:0px;" />

    This overwrites my style and removes the border! Am I losing my mind here?


    Thanks,

    Matt
     
    Matt Sollars, Mar 29, 2006
    #1
    1. Advertising

  2. Matt Sollars

    Guest

    Never noticed it until you said something. So I looked into the
    Image.AddAttributesToRender method and noticed:

    If Me.BorderWidth.IsEmpty Then
    If MyBase.EnableLegacyRendering Then
    writer.AddAttribute(HtmlTextWriterAttribute.Border,
    "0", False)
    Else

    writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "0px")
    End If
    End If

    So you're right, the border width attribute will always be rendered
    even if it is empty.
    You can get around that problem by creating a custom image class,
    override AddAttributesToRender() and remove that code block.
    or
    you can use the html image control directly.
     
    , Mar 29, 2006
    #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. tshad
    Replies:
    0
    Views:
    2,308
    tshad
    Jan 31, 2005
  2. phl
    Replies:
    1
    Views:
    4,442
    Martin Jay
    Jun 8, 2006
  3. Coder
    Replies:
    1
    Views:
    732
    Cowboy \(Gregory A. Beamer\)
    Jun 24, 2006
  4. =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=

    border-color: #003366; border-width: 2px;

    =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=, Jul 17, 2006, in forum: HTML
    Replies:
    64
    Views:
    3,636
    Adrienne Boswell
    Jul 30, 2006
  5. Ken Varn
    Replies:
    0
    Views:
    539
    Ken Varn
    Apr 26, 2004
Loading...

Share This Page