Today I was working on making SportsAlert valid against the doctype XHTML 1.0 Strict. I used http://validator.w3.org to test my homepage and fixed all of the issues except for 2. There are 2 issues inherent in ASP.NET web forms. One is that it adds name="aspnetForm" to the <form> tag, which is valid in XHTML Transitional but not XHTML Strict. Secondly, it adds input tags for things such as Viewstate right after the opening <form> tag, which is also valid in XHTML Transitional but not in XHTML Strict. To fix these 2 issues, you need to include:

<xhtmlConformance mode="Strict" />

In your web.config file within the system.web node. This will remove the name="aspnetForm" attribute from the <form> tag and will place the input tags within a div tag so that they have a valid container.

That should be enough, however for some reason the w3.org validator will still complain about these two things and when you look at the source code that it's pulling down, it's different from the real source code. The name="aspnetForm" will still be on the form tag and the input tags won't be wrapped in the div tag, when you can clearly see by doing view source on the page that those changes have been made. The solution is to add a .browser file to the App_Browsers directory in your ASP.NET application:


<browsers>
  <browser id="w3cValidator" parentID="default">
    <identification>
      <userAgent match="^W3C_Validator" />
    </identification>
 
    <capture>
      <userAgent match="^W3C_Validator/(?'version'(?'major'\d+)(?'minor'\.\d+)\w*).*" />
    </capture>
 
    <capabilities>
      <capability name="browser" value="w3cValidator" />
      <capability name="majorversion" value="${major}" />
      <capability name="minorversion" value="${minor}" />
      <capability name="version" value="${version}" />
      <capability name="w3cdomversion" value="1.0" />
      <capability name="xml" value="true" />
      <capability name="tagWriter" value="System.Web.UI.HtmlTextWriter" />
    </capabilities>
  </browser>
</browsers>

 

I didn't take the time to figure out why this works but it does and my page is now XHTML 1.0 Strict valid, so I'm happy... :)