Tuesday, July 24, 2007

Sys is undefined – in ASP.net AJAX

Sometimes, funny mistakes makes me crazy...

Today, I was facing this error during playing with a simple AJAX application. Actually the application has an update panel and couple of controls in it. And it is working smooth. But when ever, I was going to write some client side javascript onto the page I was facing the error. Here is the code.

<head runat="server">
<
title>Hello<title>
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance()
.add_pageLoaded(pageLoaded)
function pageLoaded(sender, args)
{
alert('hi');
}
</script> </head>

Spending 30 mins I did not find a good solution into the internet. Later I tried to move the script block from the head section to the body section (after the script manager declaration) and I found it is working! I hope it will save some of your vital mins…

<head runat="server">
<title>Untitled Page</title>

</head>

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

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

</asp:ScriptManager>

<div>

<script
type="text/javascript">

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);

function pageLoaded(sender, args) { alert('works'); }

Cool!

No comments:

Post a Comment