Image button found guilty of not being valid xhtml horror!!!

Standard

The .net image button seems so innocent but a trip over to w3c.org and the html validator soon exposes the terrible truth. Prepare yourself for this, sit down, have a large brandy ready… It renders border=”0″ even though you haven’t put one in there yourself! try it! Put any xhtml 1.0 transitional site into the validator:

http://validator.w3.org/

And watch in utter horror while your site is rejected as a bad example to kids everywhere.

So what is going on here? And is there anyway out?

Well after some digging I found an excellent article:

http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/ac098c63-61ff-4b53-b5ad-72cb2eb0f7f2

It turns out the validator is unrecognised as a browser type to asp.net and so is presented with html 4.0 instead of xhtml, hence the border=”0″ debarkle.

Is there a workaround? Yes there is either don’t use image buttons or put this in your web.config:

<browserCaps>
<
case match=W3C_Validator*>
TagWriter = System.Web.UI.HtmlTextWriter
W3CDomVersion = 1.0
</case>
</
browserCaps>

A solution to a weird problem, but necessary if like me you want that green tick 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *