Wednesday, April 6, 2011

'Sys' is undefined - ASP.NET AJAX

When I was using ASP.NET 2.0 along with Ajax Extensions 1.0. I received this error ‘Sys’ is undefined error message every time I used an Ajax control.

Wondering why, I search in internet and hope that I will find one of the solution. After several trial and error finally I can find the solution and it work just fine for me.
Why this error?
This error occurs specifically when you try upgrading your existing ASP.NET 2.0 Applications to AJAX by using the ASP.NET AJAX controls like UpdatePanel, etc., The common cause for this error is that you havent updated the Web.Config file of the application to enable the runtime understand ASP.NET AJAX. Let me explain a little more.

When you install ASP.NET AJAX your Visual Studio 2005 gets the toolbox updated with ASP.NET AJAX Server side controls like ScriptManager, ScriptManagerProxy, UpdatePanel, UpdateProgress etc., You already have your existing ASP.NET 2.0 application pages and you can add ScriptManager, UpdatePanel and other controls from Toolbox to your pages. When you run the page, you would get 'Sys' is undefined javascript error. The reason being that, your web.config of the existing ASP.NET 2.0 application misses certain settings that require to be added to make it understand the ASP.NET AJAX Server side controls like UpdatePanel, UpdateProgress etc.,

How to Solve the error ?
To solve the error we need to modify web.config file.
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>


0 comments:

Post a Comment