Ajax|asp.net
Recently, I've helped a few developers, who have encountered some weird javascript problems that can occur when using ASP.net AJAX and some of their custom JavaScript scripts. The main reason for the problem is that they are automatically porting vs 2003 Web projects to VS 2005, and <xhtmlconformance mode= "Legacy"/> are also configured in their Web.config files.
If you've written custom client JavaScript scripts in your Web application and will use Ajax, read on to see how to avoid this common problem.
Symptoms:
When you add a new client JavaScript script to a project that was previously successfully upgraded from VS 2003 to VS 2005, you see Strange behavior. When using the ASP.net AJAX UpdatePanel control, this strange behavior sometimes includes pages that do whole pages postback, not just incremental local updates.
When you open your Web.config file, you will see the <xhtmlConformance/> elements, like this:
<configuration>
<system.web>
<xhtmlconformance mode= "Legacy"/>
</system.web>
</configuration>
Background:
Many server-side controls in ASP.net 1.0 and 1.1 do not export XHTML-compliant identities. ASP.net 2.0 has changed this, and by default, all server-side controls will output XHTML-compatible identities.
But one of the things we noticed in the early ASP.net 2.0 beta is that when you upgrade your customer application, many applications assume that the page output is not XHTML compliant. By changing the default output of our server control to XHTML-compatible, it sometimes modifies the visual display of the page. For backwards compatibility purposes, we added this <xhtmlConformance> setting to allow developers to set controls to Legacy mode (that is, as with ASP.net 1.1, output non-XHTML identities), or transitional Schema (XHTML transitional), or Strict mode (XHTML Strict) display.
By default, this legacy configuration is added to your Web.config file when you use the VS 2003 upgrade to the Web Project Migration Wizard for VS 2005 (whether it is a Web site or Web application project).
Solution:
Unless you know there is a problem with your site in XHTML mode (but you haven't had time to correct it), I always suggest removing the <xhtmlConformance> from your Web.config file, Or you can explicitly set it to transitional or Strict.
This will make your HTML output conform to the standard, and this will also cause your server control's HTML output to be well formed, that is, the start tag and end tag always match. This is especially important when you use AJAX technology to dynamically replace the content of certain HTML elements on your page, otherwise, client JavaScript scripts sometimes confuse container elements and cause errors. It will also ensure that ASP.net Ajax will work properly on your site.