Introduction
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: http://validator.w3.org/.
Step 1: Adding Valid DOCTYPE and HTML Tags
Add this to each .aspx page or just to the .master page:
="1.0"="UTF-8"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 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:
<system.web>
<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:
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:
<body>
<form method="post" action="default.aspx" id="aspnetForm">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwULLTE3OTA2NzE4NzhkZNfmNwEXXdZH1+AqEfOHXBehT/kY" />
</div>
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:
<body>
<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:
<browsers>
<browser id="W3C_Validator" parentID="default">
<identification>
<userAgent match="^W3C_Validator" />
</identification>
<capabilities>
<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" />
</capabilities>
</browser>
</browsers>
Now, the validator will show in green: 'This document was successfully checked as XHTML 1.1!'
History
- 22.11.2008 - Rewritten according to comments.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.