I do I remove the style attribute from Image controls?

J

J055

Hi

A number of controls which use images seem to render html with a default
style attribute: style="border-width:0px;"

e.g.

<input type="image" name="ctl00$Main$ImageButton1"
id="ctl00_Main_ImageButton1" src="images/address_book.gif"
style="border-width:0px;" />

<img id="ctl00_Main_Image1" src="images/delete.gif"
style="border-width:0px;" />


I'd like to remove it from all of these controls because it's a waste of
mark-up and we use external stylesheets to style web pages.

I've tried things like this in the Load and PreRender page events but the
style refuses to disappear.

ImageButton1.Style.Clear();
ImageButton1.Style.Remove.("border-width");

Any suggestions?

Thanks
Andrew
 
K

Ken Cox - Microsoft MVP

Not an answer, but just to let you know that we ran into a similar problem
with the GridView and haven't yet found a way to remove it.

That attribute seems to be hardwired in.
 
J

J055

Hi

Thanks for the response. Looks like you're right about hardwiring. Using the
Reflector tool to disassemble the Image control I found it contained an
AddAttributesToRender method with this code tucked in at the bottom:


if (this.BorderWidth.IsEmpty)
{
if (base.EnableLegacyRendering)
{
writer.AddAttribute(HtmlTextWriterAttribute.Border, "0",
false);
}
else
{
writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth,
"0px");
}
}


I'm sorry Microsoft but that is just plain wrong!

Andrew
 
S

Steven Cheng[MSFT]

Hi Andrew,

Yes, it is a bit dummy that the style is hard coded. Currently what I can
get is using the html image server control instead or creating a custom
control to render the clear image element.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

No members online now.

Forum statistics

Threads
474,135
Messages
2,570,783
Members
47,341
Latest member
hanifree

Latest Threads

Top