Microsoft JScript runtime error: 'Sys' is undefined


Microsoft JScript runtime error: 'Sys' is undefined error is raised when trying to work with Partitial page rending inAjax enabled Website This error raises when trying to call the Sys namespace before Javascript is loaded.

Microsoft JScript runtime error: 'Sys' is undefined

Microsoft JScript runtime error: 'Sys' is undefined error is raised when trying to work with
Partitial page rending inAjax enabled Website


<script type="text/javascript" language="javascript">
// var pageInstance = Sys.WebForms.PageRequestManager.getInstance();
// pageInstance.add_pageLoaded(UpdateLabelHandler);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(PageLoadingHandler);
function PageLoadingHandler(sender, args) {
var dataItems = args.get_dataItems();
if ($get('Label2') !== null)
$get('Label2').innerHTML = dataItems['Label2'];

}
</script>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>


<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</ContentTemplate>

</asp:UpdatePanel>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
>/form>

</body>
</html>



When this code is executed you will come across the issue Microsoft JScript runtime error: 'Sys' is undefined
This error raises when trying to call the Sys namespace before Javascript is loaded.
ScriptManage intiaties Ajax Framework, updatepanel and javascript
The script in the page head tries to access the PageRequestManager long before the AJAX Framework has been fully loaded. So the error raises.

To fix the issues
Just place the Script after AJAX Framwwork is loaded.


<body>
<form id="form1" runat="server">
<div>

</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>


<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</ContentTemplate>

</asp:UpdatePanel>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</form>


<script type="text/javascript" language="javascript">
// var pageInstance = Sys.WebForms.PageRequestManager.getInstance();
// pageInstance.add_pageLoaded(UpdateLabelHandler);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(PageLoadingHandler);
function PageLoadingHandler(sender, args) {
var dataItems = args.get_dataItems();
if ($get('Label2') !== null)
$get('Label2').innerHTML = dataItems['Label2'];

}
</script>

</body>
</html>



Comments

Guest Author: Angel24 Feb 2014

In this post find a method to do it, I hope it will be useful
http://systemdeveloperpy.blogspot.com/2014/02/como-agregar-javascript-updatepanel-en.html



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: