9/16/2008

How to remove 'Sys' is undefined ?

Many of my Co – developers who are trying to integrate ASP.NET AJAX into their applications are getting this error. Even newbies who start using ASP.NET AJAX run into this error. So before we start on How to remove ‘ Sys is undefined ‘ , let me throw a light on the possible outcomes which might result in this error ?

You might had observed the ASP.NET AJAX requires to have atleast one script manager on the page where you want to use it. The script manager will render various script tags from the AJAX libraries so as to initialize and run the AJAX scripts. If you try to view source code rendered by the browser , you will find something like this .

Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('aspnetform'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(‘UpdatepanelControlsArray ’);

Note : Aspnetform, UpdatepanelControlsArray will be replaced by your page form ID and Update panelID’s separated by comma , you have on your page.

When the browser runs this code, it will expect Sys.WebForms.PageRequestManager to be defined somewhere already which happens to be in the AJAX library scripts that are loaded by the script manager.
If the browser fails to load those scripts, the script engine can’t find the definition for Sys, Sys.WebForms, Sys.WebFormsPageRequestManager, and returns the error ‘Sys’ is undefined .

Removing ‘ Sys ’ is undefined :

1.If the error is coming only in IE6 and not in other browsers ,There may be issue in compression of the scripts which will be handled by the Script resource handler. So make sure you have the latest version of AJAX Extensions and try turning off Compression in your web.config file as shown below .

<system.web.extensions>
<scripting>
<scriptResourceHandler enableCompression="false" enableCaching="true" />
</scripting>
</system.web.extensions>


2. Required Entries in web.config missing : Make sure your web.config contains the all the required entries for the AJAX to work. If you want to know required web.config entries for AJAX , Click here.

3. The virtual directory you are using for your web, may not be marked correctly as an application. Make sure you are using a web application and not just a IIS directory. In your IIS Manager right click on the virtual directory and click Convert to Application and you are done.

4. ScriptResource.axd requests return 404 :This happens as a result improper installation of ASP.NET. On a default installation of ASP.NET, any web request to a resource ending in .axd is passed from IIS to ASP.NET via an isapi mapping. Additionally the mapping is configured to not check if the file exists. If that mapping does not exist, or the check if file exists isn't disabled, then IIS will attempt to find the physical file ScriptResource.axd which if it is not able to find returns 404 error.

You can check to see if this is the problem by copy/pasting the full URL to ScriptResource.axd from the source which will be something like below and running it.

<script src="/YourWebApplication/ScriptResource.axd?[Some query string]" type="text/javascript"></script>

To fix this run "aspnet_regiis.exe" in Visual Studio command line tool to fix it up.You can run "aspnet_regiis -i -enable", which does the full registration of ASP.NET with IIS and makes sure the ISAPI is enabled in IIS6. You can also run "aspnet_regiis -s w3svc/1/root/ YourWebApplication " to fix registration of your web application.

For more solutions and Techworld Updates , Subscribe to Technova feed or click here to get updates via email .

3 comments:

Subhash,

I want to thank you for posting this information on the "sys is undefined" error. It helped me resolve my problem after having spent countless hours scouring the internet for solutions and trying different fixes to no avail. People post solutions like this in hopes that it will help at least one person. Well, I'm that one person that you saved. Thank you!!!

I was having the "sys is undefined" error only in Internet Explorer, and only behind my company firewall. All other browsers worked fine. At home, I didn't get this error in IE.

To resolve it, it copied and pasted the system.web.extensions block from above into my web.config. That's all it took, and the errors were gone.

Thanks again Subhash.

Just like any generic pharmaceutical, Zenegra Generic Viagra online are less expensive than the brand name equivalent cheap Viagra . The reason that you can buy Zenegra generic Buy Cialis for less at a online drugstore is that you don't pay for branding, marketing, advertising or a costly sales force or overhead. The cost savings are past directly on to you.

Here's something that work for me when using windows 2003

http://aspadvice.com/blogs/sswafford/archive/2007/01/25/ASP.NET-AJAX-v1.0-Sys-is-undefined-error.aspx

Post a Comment