Image Server Control's Style/Border

M

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
 
C

CaffieneRush

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.
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top