Getting 'Sys' is undefined error on one page only.

J

John Kotuby

Hi all,

On several pages I am using JavaScript to keep track of PageRequestManager
events. Here is the code:

<script type="text/javascript">
//================================================================
var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequestHandler);
var postBackElement;

Of course there are other JavaScript functions not shown here and there is a
closing </script> tag.
I have an asp:ScriptManager declared on every page that I use this
technique.
The only major difference that I see in the page that throws the error is
that it is not wrapped in a Master Page.
The pages in which run fine with the exact same JS call have the...
var prm = Sys.WebForms.PageRequestManager.getInstance();
....located within the <asp:Content> tags.

While seaching for answers ( most of which state that there must be missing
elements in web.config), I came across one person who said it is possible
that the JavaScript is being run before the page completely loads.

I am presuming that my entries in web.config are correct because the call to
Sys.Webforms in all my other pages works just fine.

Does anyone have an idea what might actually be causing this error in one
page only?

Thanks for any help.
 
J

John Kotuby

John Kotuby said:
Hi all,

On several pages I am using JavaScript to keep track of PageRequestManager
events. Here is the code:

<script type="text/javascript">
//================================================================
var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequestHandler);
var postBackElement;

Of course there are other JavaScript functions not shown here and there is
a closing </script> tag.
I have an asp:ScriptManager declared on every page that I use this
technique.
The only major difference that I see in the page that throws the error is
that it is not wrapped in a Master Page.
The pages in which run fine with the exact same JS call have the...
var prm = Sys.WebForms.PageRequestManager.getInstance();
...located within the <asp:Content> tags.

While seaching for answers ( most of which state that there must be
missing elements in web.config), I came across one person who said it is
possible that the JavaScript is being run before the page completely
loads.

I am presuming that my entries in web.config are correct because the call
to Sys.Webforms in all my other pages works just fine.

Does anyone have an idea what might actually be causing this error in one
page only?

Thanks for any help.

OK... for anyone who might have the same problem, it appears that the poster
who said it's possible that the JavaScript was being run before the entire
page loads is correct. To resolve the situation, at the top of the page I
simply declare the public JS variables along with a window.onload event
handler. It is there that I make the call to Sys.Webforms as below...

<script type="text/javascript">
//==================================================
window.onload = window_onload;

var prm
var postBackElement;

//=================================================
function window_onload()
{
prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequestHandler);
}

I no longer get the error.

Since I use these JS functions in several places they should probably be in
a JS library.
However, I am concerned that if I use that approach then the order of JS
firing might not be what I expect.

Thanks to anyone who might have already answered my post.
 
B

bruce barker

this is why you should use ScriptManger.RegisterStartupScript. it will
render the script after sys is defined.

-- buce (sqlwork.com)
 
J

John Kotuby

Thanks Bruce,
I will look into that approach. I didn't see your response until this
morning.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top