Click here to Skip to main content
14,659,852 members
Articles » Web Development » ASP.NET » Howto
Posted 25 Nov 2008

Tagged as


17 bookmarked

W3C_Validator with ASP.NET or how to validate XHTML 1.1

Rate this:
4.00 (1 vote)
Please Sign up or sign in to vote.
4.00 (1 vote)
25 Nov 2008CPOL
This article is from a public bug list of W3C, describing errors in XHTML 1.1 validation of ASP.NET pages.


This is all about standards. When you want to write a new web browser, you need to start from the start. But what is start? Standard, of course. Your new web browser has to implement a standard or a couple of standards. You probably have heard about HTML, it comes from 'hyper text markup language', the first standard for web pages. So, when your application validates to a standard and the web browsers have implemented the same standard, you may be sure your page will look the same on each of them.

XHTML is a new generation standard, the next step from HTML, that on its mission holds to separate program code from presentation level. According to it, you have to place all presentation markups into style sheets. More about XHTML 1.1 can be read here. Introduces in 2001, so not so new, but even today, not many websites can be validated against this.

Making your website valid against XHTML1.1 not only shows you as someone who understands the problem and strength of standardization, it also makes your web application be more manageable and teaches you to make it more logically constructed.

Let's make W3C-validator happy

The best way to start with validation check is the source, of course:

Step 1: Adding Valid DOCTYPE and HTML Tags

Add this to each .aspx page or just to the .master page:

<?xml version="1.0" encoding="UTF-8" ?>


<html xmlns="" xml:lang="en">

Step 2: Bringing ASP.NET Application into 'Strict' Mode

This is the most simple action. Just add this line to the web.config file:

      <xhtmlConformance mode="Strict" />

Step 3: Cleaning Markup

Make all markups according to the XHTML standard.

Step 4: Going crazy... joke

Every step with ASP.NET is done, but these two errors stay:

Image 1

What do we do? Yep, this question can make you mad, 'cause you have cleaned your code, and all markups are clean'.

When you view the source code of the response, you will see:

    <form method="post" action="default.aspx" id="aspnetForm">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"

value="/wEPDwULLTE3OTA2NzE4NzhkZNfmNwEXXdZH1+AqEfOHXBehT/kY" />

which is valid against XHTML 1.1, but when you check with the W3C validator, it shows those errors and the source code will look like this:

<form name="aspnetForm" method="post" 

   action="default.aspx" id="aspnetForm">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"

value="/wEPDwULLTE3OTA2NzE4NzhkZNfmNwEXXdZH1+AqEfOHXBehT/kY" />

Where is the problem? ASP.NET and .NET Framework v2.0 (v3.0, v3.5) do not include the Validation Service engine in their recognized browsers and the rendered code gets 'down-leveled' when rendered. This produces the errors in code that are sent to the Validation Service engine thus causing the code not to validate. (Craig Thacker comments at W3C bugzilla).

So, as a workaround, you have to assign the W3C validator client by yourself.

Step 4: Assign W3C Validator Capabilities

Create the App_Browsers folder in the web root directory, and a file with .browser extension. It must contain this code:

<!-- App_Browsers/w3g.browser
    <browser id="W3C_Validator" parentID="default">
            <userAgent match="^W3C_Validator" />
            <userAgent match="NewBrowser (?'version'\d+\.\d+)" />
          <capability name="browser"              value="W3C Validator" />
          <capability name="ecmaScriptVersion"    value="1.2" />
          <capability name="javascript"           value="true" />
          <capability name="supportsCss"          value="true" />
          <capability name="tables"               value="true" />
          <capability name="tagWriter" value="System.Web.UI.HtmlTextWriter" />
          <capability name="w3cdomversion"        value="1.0" />
    <browser refID="Mozilla">
            <capability name="xml" value="true" />

Now, the validator will show in green: 'This document was successfully checked as XHTML 1.1!'


  • 22.11.2008 - Rewritten according to comments.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ukraine Ukraine
No Biography provided

Comments and Discussions

-- There are no messages in this forum --