You might receive the error 'Sys' is undefined when running ASP.NET AJAX Web pages or trying to AJAX enable your exisitng Web Applicaitons.
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.,
Resolution
To resolve the issue, I am providing herebelow the steps:-Open the Web.Config file and start adding the following settings to the same:- (Forewarning: Modifying Web.Config incorrectly makes your site inaccessible and I would suggest you take a back up of your existing web.config file before making the following changes. This article is intended for people with prior experience in dealing with web.config file, settings etc., and if you arent very convenient working with the Web.Config file, make your administrator or other experienced developers make these changes) 1. Below the
What we have done in this step is registering the System.Web.Extensions namespace, the assembly and its various handlers that are useful in handling AJAX for your ASP.NET 2.0 Application.2. Then, below the
In this step, we registered the tagprefix of ASP for the ASP.NET AJAX Server controls like UpdatePanel so that we can use the same 3. Then find the
This step enables compilation for your website and adds the reference assembly for System.Web.Extensions.4. Then below the compilation settings (above step), add the following:-
What we have done here is to register the Http Handler and specify that Web Services might be handled using Javascript (asynchronous callback) as well as add the ScriptModule Http Module.5. Then, after the
In this step, we have additional steps where we can play with JSON Serialization settings and enabling some of the Application Services like AuthenticationService, ProfileService etc.,6. Thereafter, add the following system.webServer settings:-
The above steps registers the ScriptHandlerFactory for Webservices and the AXD that needs to handle the requests.Once you have added the above steps to your web.config file, you would be able to add ScriptManager, UpdatePanel and other ASP.NET AJAX Controls and would be able to run the page. This should solve the 'Sys' is undefined error message.These settings are not required if you are creating a "File - New - AJAX Enabled Website" using Visual Studio 2005 since all the above settings are added automatically to your web.config file.
Visual Studio 2008
Similarly, with Visual Studio 2008 any ASP.NET Website created will automatically have these settings as a part of the web.config file enabling you to directly use the ASP.NET AJAX Server side controls as well as the client scripts.
No comments:
Post a Comment