Both are caused by xhtmlconformance nodes-ASP. NET Ajax failure

Source: Internet
Author: User
Difficult: Do not use & lt; xhtmlconformance mode = & quot; legacy & quot;/& gt; in ASP. NET Ajax;

[Original address] Gotcha: Don't use <xhtmlconformance mode = "Legacy"/> with ASP. NET Ajax
[Original article posting date] Sunday, December 10,200 pm

Recently, I have helped several developers who have encountered some strange JavaScript problems that may occur when using ASP. NET Ajax and some of their custom JavaScript scripts. The main cause of the problem is that they automatically transplanted the vs 2003 web project to VS 2005 and configured <xhtmlconformance mode = "Legacy"/> in their web. config file.

If you have compiled a custom client Javascript script in your web application and will use Ajax, read it and learn how to avoid this common problem (note: if you want to view other tips posted by me, click here to view the list of tips and FAQs ).

Symptoms:

When you successfully Add a new client Javascript script to a previously upgraded project from vs 2003 to VS 2005, you will see strange behavior. When using the ASP. NET Ajax updatepanel control, this strange behavior sometimes involves page-wide PostBack, not just incremental local updates.

When you open your web. config file, you will see the <xhtmlconformance/> element, as shown in the following figure:

<Configuration>

<System. Web>
<Xhtmlconformance mode = "Legacy"/>
</System. Web>

</Configuration>

Background:

Many server-side controls in ASP. NET 1.0 and 1.1 do not output XHTML-compatible identifiers. ASP. NET 2.0 has changed this. By default, all server-side controls will output XHTML-compatible Identifiers (Note: you can learn more about ASP from this excellent msdn article.. NET 2.0 ).

However, one thing we noticed in the early ASP. NET 2.0 Beta was that when we upgraded the customer application, many applications would assume that the page output is not compatible with XHTML. If we change the default output of the control on our server to be compatible with XHTML, it sometimes modifies the visual display of the page. For the purpose of backward compatibility, we have added the above <xhtmlconformance> Settings, allowing developers to set controls in the legacy mode (that is, with ASP. NET 1.1, it outputs non-XHTML identifiers), transitional mode (XHTML transitional), or strict mode (XHTML strict.

By default, when you use vs 2003 to upgrade to VS 2005 web project porting wizard (whether it is a website or web application project), your web. this legacy configuration is added to the config file.

Solution:

Unless you know that there will be problems when your website runs in XHTML mode (but you don't have time to correct it), I always recommend that you use the web. remove <xhtmlconformance> from the config file, or you can explicitly set it to transitional or strict.

This will make your HTML output conform to the standard. In addition, this will also cause the HTML output of your server control to be well formed, that is, the start tag always matches the end tag. This is especially important when you use Ajax technology to dynamically Replace the content of some HTML elements on your page. Otherwise, the client Javascript script sometimes cannot clearly understand the container elements, leading to errors. It will also ensure that ASP. NET Ajax will work properly on your website.

I hope this article will help you,

Scott

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.