Thursday, May 25, 2006

Making width and height of ASP:ImageButton to work with Safari and other browsers

If you ever come across the problem of using with specified width and height, it will work fine with the IE but the image dimensions will not be set for other browers like safari, the reason behind it is, whenever you specify the width and height of the it genertaes the Style attribute whenever HTML is rendered and embed the width and height in to it, which works fine in case of IE only.

So what do you need to make it work in each and every web browser. You need to add the width and height attributes to the object using imgBtn.Attribute.add("width","20"), then it will work fine for each and every brower.


if you have such code

" asp:imagebutton id="ImageButton1" runat="server" width="50px" height="20px" "

the HTML code generated by it is:

{ input type="image" name="ImageButton1" id="ImageButton1" alt="" border="0" style="height:20px;width:50px;" }

it works fine with IE but not with any other browser

so what needed to be changes, we need to add this

" asp:imagebutton id="ImageButton1" runat="server" "


now the HTML genertaed will be:

{ input type="image" name="ImageButton1" id="ImageButton1" alt="" border="0" height:20px width:50px }


No comments: