views:

99

answers:

3

Hi Geniuses

I got a complicated problem with ASP.Net 4.0 Ajax....I started a website with Visual Studio 2010 on my machine,and added some update panels they used to work fine,but suddenly i got that series of errors when i run my website

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

Microsoft JScript runtime error: 'Sys' is undefined

The strange things is that i made a website on the same machine with VS 2010 and the update panels there work perfectly.i took its web.config to my new website and changed just the connection..and i got the same error

I tried to search for a solution but i failed to find any real solution.Can anyone help?

+1  A: 

This is a common error that happens when you try to call framework javascript function before page have even loaded them.

So ether run your code when dom is ready (eg pageload), ether place your code after the scriptmanager tag, or check to place it after the javascript load from scriptmanager.

Aristos
How can i do that? and yes the script manager is in the top of my master page,but even when i created a new blank page,with only a label and a button in an update panel,,i received the same error
Khaled
@khaled can you see the source code of your page (right click on browser and select source code). Then check the line that you get the error. Maybe there are elements in your page that you have setup them on web.config ?
Aristos
@Aristos thanks for your reply,i tried to bug the page with firebug and changed the line which fire the error after all the scripts references,,that did not let all the page post back when a control in an update panel posts back..it happens with no action...i started a new blank website and imported my pages,app_code and BIN folders..it worked fine,,but later again without changing anything i got the same error. :(
Khaled
@khaled Do you use gzip ? for compressing your page ?
Aristos
@Aristos No at all..i reinstalled the VS 2010 on my machine and even tried to open the website on another machine that has VS 2010 and i got the same error.I am really frustrated from that strange error!
Khaled
@khaled there is a case that your web.config is not setup the right way. Search on google for the "Ajax client-side framework failed to load".
Aristos
@Aristos i tired that already,but you now in Asp.Net 4.0 the web.config is cleaner than the previous versions,i have not changed anything in the web.config,and all the related posts i found through Google about previous versions. :( ,Thanks for your attention
Khaled
@Aristos i found a post on Asp.Net forum,the post said that after adding routing to the website it started to show that error,i removed all the related code to routing and now there are no errors and ajax works fine,What could be the reason as i want them both to work?
Khaled
@khaled maybe is lost the path of the WebResource.axd file from the rules of the routing. You can open the page of the render html and see where is search to locate the WebResource - if this is not found then the library with javascript is not loaded and the sys not found error appear.
Aristos
@Artistos,,yeh it is the reason,,the routing messes the reference,,i am searching for a solution
Khaled
A: 

Here is the answer by zhughes from this thread on asp.net forum.

The Reason : the path of the javascript generated by the scriptmanager changes when the URL Routing module is used.

The Solution : Tell the routing API to not route the files with "axd" extension (the files generated by the scriptmanager)

Add this rule to the method where you register the routing rules in Global.asax

 routes.Ignore("{resource}.axd/{*pathInfo}");

in addition you should have this section in web.config

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
Khaled
A: 

I had this problem and sought an answer from the almighty Google, tried various suggestions including the ones above but had no luck. Gave up and moved on to other work, came back a few days later and the problem had disappeared.

I resumed work, made some code changes and published my website and the problem reappeared. Went back to the Google and came across someone who had the problem while using the 3.5 framework. In that case s/he was able to resolve the problem by going to the 'Add/Remove Programs' control panel and selecting the repair option.

I did likewise, repairing the 'MS .NET Framework 4 Client Profile' and 'MS .NET Framework 4 Extended'. That fixed the problem for me.

Hope that solves it for someone else.

kannankeril