Making ASP.NET XHTML Compliant

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

Leave a Reply

Latest Posts

Testimonials

"Amar clearly has a thorough knowledge of Sharepoint, this knowledge, coupled with his professionalism and dedication made him a tremendous asset to the project. He was the key contributor to the later stages of the project delivery effort (the really difficult bit, long hours and hard work that puts huge demands on people), and I can state categorically that without his focussed dedication and hard work we would not have been able to meet the timescales imposed upon the project."

Tim Ellis , Sharepoint Project Manager , Royal Bank of Scotland

Subscribe Now