Wednesday, March 28, 2012

Why Sys.Application does not work?

I just begin to learn ASP.NET AJAX. I have a simple question, please bear with me. I want to test client-side page life cycle. Here is my code. I don't know why pageInit does not get called? But pageUnload works.

Thanks a lot!

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

<script type="text/javascript">
<!--
Sys.Application.add_init(pageInit);


function pageInit()
{
alert("Enter init page.");
}


function pageUnload()
{
alert("Page unloaded!");
}
//-->
</script>
</head>
<body>
<form id="form1" runat="server">

.....

Try putting your Sys.Application.add_init(pageInit) *after* you've defined your pageInit function.


I think I got a error that Sys is undefined. Did I miss including any namespace?

Thanks again!


The problem is fixed. I need to move <script> section after <asp:ScriptManager ID="ScriptManager1" runat="server" />, so that Sys can get reference.


I expierence the same problem, IE7 throws a javascript error "sys is undefined".

I did like you described and put the <asp:ScriptManager> section before my first <script> tag, but it doesn't help.

Have to put the ScriptManager section into my masterpage aspx file because of the <form> tag, could this be the problem?
In the browser output file of my aspx there are still <script> tags above the ScriptManager.

What can I do on this?


Check out this post for ideas about why you might get "sys is undefined":http://weblogs.asp.net/chrisri/archive/2007/02/02/demystifying-sys-is-undefined.aspx.

I guess it probably is the web configuration issue. Create a new AJAX-based web project, copy its web.config to your project to see if it works.

No comments:

Post a Comment