Home All Groups Group Topic Archive Search About

Image Server Control's Style/Border

Author
29 Mar 2006 6:08 PM
Matt Sollars
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

Author
29 Mar 2006 8:24 PM
CaffieneRush@gmail.com
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.