i am using an asp:ImageButton server control; i set the CssClass attribute to my CSS style, in which i defined border:solid 1px red;
.NET automatically renders an inline ‘style’ attribute as follows:
style='border-width:0px;'
Q1. Can i remove the automatic inline ‘style’ ? e.g. on the PreRender perhaps inspect the HTML and edit it? I have tried Attributes.Remove(‘style’) but this does not work (strangely enough does not error either), and i remember reading somewhere i can only remove the attributes that i added manually.
My workaround was to assign BorderWidth=1px property in the aspx page, but what’s the point in providing a CssClass property if it’s going to be overridden anyway (automatically!) Bug or Feature?
The reason they do this is due to a legacy of HTML where images default to have borders when they have a
<a>tag wrapping them. In most situations people don’t want these borders which is why ASP.NET does what they do. In order to get around this, you can do the following in your style sheet (assuming you are settingcssclass='redborderbutton'):