Justin Toth's Blog

Justin is a web developer living in Maryland

Making your ASP.NET web forms app valid with XHTML 1.0 Strict

clock March 19, 2010 13:01 by author Justin Toth

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... :)



SportsAlert Facebook Application

clock March 12, 2010 21:40 by author Justin Toth

A while ago I posted on developing facebook applications with ASP.NET MVC and the .NET Facebook API. At the time I was developing on a Windows XP box, which runs IIS 5. ASP.NET MVC routing is intended for IIS 6 and above, so it was a painful process. Now that I'm on Windows 7 with IIS 6.5 I decided to come back to that project and give it a try. Amazingly everything just started working without any code changes.

Without further ado, here is the SportsAlert Facebook application:

http://apps.facebook.com/sportsalert/

This app is very simple, allowing you to sign up for SportsAlert and subscribe to teams from within the Facebook app. For the teams you pick, you will get text messages at the end of the games. If you want to subscribe to individual games and/or change the frequency of your alerts (on score change, on quarter change, etc...) then you can login automatically to the SportsAlert web site from the facebook app.



About the author

Justin

Justin is a senior developer who has been working with .NET since 2003. His main focus is building highly-interactive web applications using ASP.NET MVC and Dojo or jQuery. Visit his company's site at http://tothsolutions.com.

Page List

Sign in