Tuesday, March 3, 2009

ERROR: "Microsoft JScript runtime error: ASP.NET Ajax client-side framework failed to load" When using AJAX

I added some AJAX functionality to an existing AST.NET website. It was my first experience with AJAX.NET.
I started with a simple tutorial, built a new small web site with AJAX, and everything worked just fine.
Then I tried to implement it to my existing website.
First I had to upgrade the website from .NET 2.0 to .NET 3.5, to enable the java controls. I am working with Visual Studio 2008, but I set the website to 2.0, so that I could work with it on my laptop, where I had the previous version of visual studio.
After upgrading the website to version 3.5 of .NET, I added a very simple AJAX control: I wrapped an existing button with UpdatePanel, to prevent page refresh when the button is clicked.
When I ran the website, I got the error message:

Microsoft JScript runtime error: ASP.NET Ajax client-side framework failed to load.

I started searching the web for this error. Many programmers met this error message, and it seemed like the suggested solutions were of two types:

1. Checking if AJAX extension was properly installed - which is irrelevant to me, because I work with Visual Studio 2008 where AJAX is built-in, and also the simple AJAX website worked fine.
2. Set the web server - the IIS - to recognize *.axd files. Again it could not apply to me because I was running everything locally, through Visual Studio, and I don't even have IIS installed on my machine.

I went on searching and researching the problem, and found on some forum some semi-cryptic comment about wrong HttpHandlers on the Web.config files.
When I looked at my Web.config file, I could not find any HttpHandler or something like that.
It turned out that a whole section was supposed to be added to the Web.config file when I upgraded the website from .NET 2.0 to .NET 3.5, and for some reason this section was not there. Seems like something went wrong in the upgrade process. When I did the upgrade again, I could see the section about the handlers in the Web.config file, and this time everything worked just fine. This is part of what was missing in the Web.config that is relevant:

<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" .../></modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode..."/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" .../>
<add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" .../>
</handlers>


Seems like it has something to do with recognizing the script files generated for the client side AJAX implementation.

Anyway, after fixing the Web.config file, the error code disappeared and AJAX works just fine.

No comments:

Post a Comment