Microsoft JScript runtime error: 'Sys' is

2019-02-11 19:03发布

问题:

I have a page with the following code on it:

<script type="text/javascript" language="javascript">
    /// <reference name="MicrosoftAjax.js" />

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

    function EndRequestHandler(sender, args)
    {
        ToggleTimeDiv();
    }
</script>

When the page loads I get the following error:

  • Microsoft JScript runtime error: 'Sys' is undefined

I'm using Visual Studio 2008 Standard Edition. What is causing this error?

回答1:

Is your <script> block ahead of your ScriptManager?



回答2:

You should place your script code at the end of your page, after all your content but just before the end tag. between end form tag and end body tag Here’s the code you need, in its rightful place:

   <html>

  ...
   </head>
   <body>
    <form id="form1" runat="server">
     ...
    </form>


    enter code here
     <script type="text/javascript" language="javascript">
  /// <reference name="MicrosoftAjax.js" />

  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

  function EndRequestHandler(sender, args)
  {
      ToggleTimeDiv();
  }
  </script>




   </body>
      </html>


回答3:

Do you have

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

at the top of your page.. I had same problem.. added this and it works...



回答4:

If you're using ASP.NET routing, use this line in your global.asax

    void Application_Start(object sender, EventArgs e)
    {
       RouteTable.Routes.Ignore("{resource}.axd");
    }