Sys is undefined

Viewed 136729

I have an ASP.Net/AJAX control kit project that i am working on. 80% of the time there is no problem. The page runs as it should. If you refresh the page it will sometimes show a javascript error "Sys is undefined".

It doesn't happen all the time, but it is reproducible. When it happens, the user has to shut down their browser and reopen the page.

This leads me to believe that it could be an IIS setting.

Another note. I looked at the page source both when I get the error, and when not. When the page throws errors the following code is missing:

<script src="/ScriptResource.axd?d=EAvfjPfYejDh0Z2Zq5zTR_TXqL0DgVcj_h1wz8cst6uXazNiprV1LnAGq3uL8N2vRbpXu46VsAMFGSgpfovx9_cO8tpy2so6Qm_0HXVGg_Y1&amp;t=baeb8cc" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
//]]>
</script>
31 Answers

Try setting your ScriptManager to this.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" /> 

I hate adding to such a huge topic and so much later, but I've think I have a solution that works in VS2015 at the very least.

I was on a hunt to find a reason for the sys error, and the only solution that worked for me was to add EnableCdn="true" in a ScriptManager like this:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnableCdn="true" />

See the MSDN for more information.

Why do we need to do this?

When working on a asp.net web application, you have to enable CDN so that Microsoft can download the Sys. library.

There was probably a script in your page that was using the Sys function. Setting EnableCdn="true" would ensure that the Sys library is downloaded before it is used.

What's CDN?

It stands for "Content Delivery Network" and enabling it allows certain resources to download with simple references.

A quote from https://www.sitepoint.com/7-reasons-to-use-a-cdn/

Most CDNs are used to host static resources such as images, videos, audio clips, CSS files and JavaScript. You’ll find common JavaScript libraries, HTML5 shims, CSS resets, fonts and other assets available on a variety of public and private CDN systems.

Both Google and Microsoft have CDNs. All you have to do is add a reference. Usually CDNs are added via a script resource:

<script src="https://ajax.aspnetcdn.com/ajax/4.5.1/1/MicrosoftAjax.js" type="text/javascript"></script>

Once you set EnableCdn="true" and Microsoft will add it's little CDN reference (like the one above) in the page which downloads the Sys library.

I hope that helps anybody that ran into the same issue.

In addition to ensuring you have the ScriptManager on your page you need to ensure that your web.config is appropriately configured.

When ASP.NET AJAX 1.0 was released (for .NET 2.0) there was a lot of custom web.config settings which added handlers, controls, etc.

You'll find the config info here: http://www.asp.net/AJAX/documentation/live/ConfiguringASPNETAJAX.aspx

Make sure that any client scripts you have that interact with .NET AJAX have the following line at the end:

if (typeof(Sys) !== 'undefined')  Sys.Application.notifyScriptLoaded();

This tells the script manager that the whole script file has loaded and that it can begin to call client methods

I was having this same issue and after much wrangling I decided to try and isolate the problem and simply load the script manager in an empty page which still resulted in this same error. Having isolated the problem I discovered through a comparison of my site's web.config with a brand new (working) test site that changing <compilation debug="true"> to <compilation debug="false"> in the system.web section of my web.config fixes the problem.

I also had to remove the <xhtmlConformance mode="Legacy"/> entry from system.web to make the update panel work properly. Click here for a description of this issue.

Was having a similar issue, except that my page was consistently generating the Sys is undefined error.

For me the problem stems from the fact that I've just installed the AJAX 1.0 extension for .NET 2.0 but had already created my web project in Visual Studio.

When tried to create AJAX controls I kept encountering this error, I spotted Slace's and MadMax1138s posts here. And figured it was my web.config, I created a new project using the new "AJAX enabled web site" project type, and sure enough the web.config has a large number of customizations necessary to use the AJAX controls.

I just updated that web.config with the web.config updates I had already made myself and dropped it into my existing project and everything worked fine.

I know this is an old thread but I found a somewhat unique solution. In my case I was getting the error because I am using both Webforms and MVC in the same ASP.NET web application. After mapping routes the issue showed up. I fixed it by adding the following code to ignore routes for both "{resource}.aspx/{*pathInfo}" and "{resource}.axd/{*pathInfo}"

    private void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
           "Default", 
           "{controller}/{action}/{id}", 
           new { controller = "Test", action = "Index", id = UrlParameter.Optional }
       );
    }
Related