You are currently browsing the category archive for the ‘ASP.NET’ category.

Wonder why many a times your ASP.NET website on migration from .NET 1.1 to .NET 2.0 starts giving all sorts of Javascript/AJAX errors? Why things don’t seem to work even when no code changes are made? Why Javascript works on your development environment but not on the production server? The reason behind all these problems is the web.config element ‘xhtmlConformance’.

What happens?

On migration from .NET 1.1 to .NET 2.0, the configuration element <xhtmlConformance  mode=”Legacy” /> is automatically added to you web.config file.

There are basically three values xhtmlConformance element can have:

  • Legacy (which is similar to how markup was rendered in previous versions of ASP.NET)
  • Transitional (XHTML 1.0 Transitional)
  • Strict (XHTML 1.0 Strict)

Why do the errors surface?

  • By default for many .NET 1.0 & .NET 1.1 servers controls, the rendering  is not XHTML compliant. ASP.NET 2.0 changed this and by default emits XHTML compliant markup from all controls
  • When xhtmlConformance is set to “Legacy” mode, it forces the controls to render in non XHTML compliant markup. What this does is, changes the ClientIDs generated for server controls
  • Most of the Javascripts use hardfixed ClientIDs for server controls. When the ClientIDs change, the Javascript is unable to locate the desired object/control & fails
  • For using AJAX, XHTML compliance needs to be met and hence this configuration will cause trouble in case you desire to use AJAX
  • Most websites have different web.config files for different environment i.e. development/testing/staging/production. In such cases the same code seems to work on one environment but not on the other because of difference in ‘xhtmlConformance’ element configurations

How to resolve these issues?

  • Remove ‘xhtmlConformance’ element from you web.conf file
  • Check for possible Javascript errors. If NO errors are found – ‘You’re so damn LUCKY!’
  • If you face Javascript errors, debug the Javascript, verify the ClientIDs generated on Page and those used by your Javascript. Usually, you will be able to resolve your problems by removing the extra ‘_’ from your Javascript ClientIDs

Hope it helps! 🙂

Archives

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 2 other subscribers

Blog Stats

  • 1,384 hits