Home All Groups Group Topic Archive Search About

I do I remove the style attribute from Image controls?

Author
6 Apr 2006 2:33 PM
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

Author
6 Apr 2006 5:56 PM
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.

Show quoteHide quote
"J055" <j055@newsgroups.nospam> wrote in message
news:OeANjcYWGHA.2476@TK2MSFTNGP05.phx.gbl...
> 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
>
>
>
>
Author
6 Apr 2006 7:21 PM
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
Author
7 Apr 2006 3:44 AM
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.)