Monday, 28 January 2008

ASP.Net AJAX Not Working (Full page postback)

The conversion process from VS 2003 to VS 2005 for web projects may result in strange behaviour when adding new client-side JavaScript to the project. For me this was evident when using ASP.Net AJAX UpdatePanel controls, which resulted in a page performing a full-page postback instead of a partial page postback of the desired AJAX page elements.

ASP.Net 1 and 1.1 did not emit XHTML compliant markup from countless server controls. ASP.Net 2 changed this and defaults to emitting XHTML compliant markup from all controls. Beta testing of ASP.Net 2 showed Microsoft that this could affect certain web apps and to prevent this a xhtmlConformance setting was introduced and added in the conversion to the config file:

<system.web>
   <xhtmlConformance mode="Legacy" />
</system.web>

If you are having ASP.Net AJAX issues I recommend removing the <xhtmlConformance> section from your web.config file or perhaps set it to Transitional or Strict.

The good new about this is it will result in your HTML from your server controls to be well formed (i.e. all tags are closed for all elements). Important in ASP.Net AJAX implementations because AJAX dynamically replaces the contents of HTML elements on your web page. If the tags aren't well formed, the AJAX JavaScript can get it's knickers in a twist with regards to the containers it should be updating, resulting in big problems.

Tip

It's also worth checking the framework's web.config file for the setting if you think this is affecting you and the setting isn't in your app's web.config

25 comments:

Brick said...

i've been searching all over, and this is the only solution that I can find. however, my application only does the full postback if i'm running it via IIS 7. If I run my app thru Cassini, it runs without full page postbacks. this happens even when I create a new ajax enabled site. meaning my webconfig does not even have the 'xhtmlconformance' section. if i create a new project it has no problems, because a new project uses Cassini (the integrated web server), versus a new website which will use IIS.

this is happening to me on my Vista Ultimate machine. I have had the OS for over a year, and never noticed it, because I typically create a new project...but recently started choosing to create a new website, where i've since found this issue.

Brick said...

grrrrr...

so I figured out my problem. it WAS the xhtmlConformance mode="Legacy"

my problem was that I forgot about it at the root. i was only looking at the web config for my app.

Neil kilbride said...

Glad you figured it out brick :)

Neil kilbride said...

I did mean to make it clear to check the framework's config too. I'll update now.

Brick said...

thanks for the post. i guarantee this will be a very popular page when the other developers out there move to Vista and start using IIS7.

Mark said...

Thanks a mil! Something so simple but so easily overlooked. It's taken quite a bit of searching to find this. Great solution thanks for your help!

Anonymous said...

Thanks very much....woooow

Anonymous said...

Wow - what a lifesaver! After searching google for two days, and repeatedly banging my head against a wall, I stumbled upon this blog. The setting did not exist in any of the web.config files, but adding <xhtmlConformance mode="Transitional" /> to my local file solved it! I don't know why this isn't more publicized.

gfutfy said...

welcome to the wow power leveling, cheap service site, buy cheap wow gold,wow gold,world of warcraft power leveling buy wow power leveling

vaidhe said...

Thanks a lot for posting this. I was updating an existing site that was upgraded from 1.1 to 2.0. The page was always doing a full post back and your solution of adding the <xhtmlConformance mode="Transitional"/> fixed it.
Thanks again.

JonP said...

My LOVE! :) You saved my day.

Anonymous said...

Thank you!

Anonymous said...

THANK YOU!!!!! This solved my issue

Anonymous said...

I just had to thank you for this post!!! You really are a life saver!

Thanks!

Anonymous said...

AWESOME! Thank you! I've been trying to figure this out for 2 hours.

vfdvgf said...

If you are eq2 plat looking buy ffxi gil as well as FFXI Gil WOW Power final fantasy gil Leveling lotro gold and World Of eve isk When you aoc gold need lineage 2 adena someone FFXI Gil to Maple Story mesos listen,world of warcraft gold I'll be 2moon dil there.lord of the rings gold When world of warcraft power leveling you world of warcraft power leveling need Guild Wars Gold a hug,final fantasy gil I'll be age of conan gold there.

Michel said...

I just stumbled upon your blog and it solved my issues as well.
Thank you.

latif said...

Thank you for sharing this solution with us... I saved my hours

Anonymous said...

Hi, Creating new ajax enable web application project and copy the web.config file was solving my proble. thanks .

Anonymous said...

米蘭情趣用品情趣用品情趣飛機杯自慰套充氣娃娃AV女優按摩棒跳蛋潤滑液角色扮演情趣內衣自慰器穿戴蝴蝶變頻跳蛋無線跳蛋電動按摩棒情趣按摩棒丁字褲G點SM後庭

視訊美女視訊做愛


網頁設計
網頁設計

paulwhit said...

Thanks!! This saved me a bunch of time. Wish I found it 2 hours ago. :)

Anonymous said...

Please accept a kiss on your feet. You da man! 2 days and half my hair later...I find this. Thank you thank you thank you!!

coson said...

I too was having a problem with AJAX not working properly on IIS 7 and after scouring the NET for hours, I came across this gem.

Naturally the problem *wasn't* in the web.config, but in the application root web.config.

I don't normally compliment posters for their contributions, but in this case, it is well deserved! Thank you so much.

Ike Ellis said...

Thanks, Neil. This solution worked great. I linked this article from my blog, too.

YOGESH MAHAJAN said...

Thank you very much.