Making ASP.NET XHTML Compliant
November 12th, 2008 // 8:48 am @ Amar
ASP.NET by default does not emit XHTML compliant code. Consider this scenario. You have carefully created an XHTML compliant design. Created your pages using ASP.NET and when you try to validate your page, it fails with the error :
Line x, Column y: there is no attribute “name”.
<form name="aspnetForm" method="post" action="Default.aspx" id="aspnetForm">
This leaves you a bit stunned, as ASP.NET adds the name tag to the form on compile and you don’t have any control over it. However, don’t worry. There is a solution.
Just add to following under system.web in your web.config file.
<
xhtmlConformance mode=“Strict” />
ASP.NET should generate compliant code now, and you should see the following in your rendered output.
<form method="post" action="default.aspx" id="aspnetForm">
As you see, it does not render the name tag anymore. Problem solved. Time to display the W3C Validated icons on your page with pride
Category : dotNet