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

Discussion in 'ASP .Net' started by John Kotuby, Dec 19, 2008.

  1. John Kotuby

    John Kotuby Guest

    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.
     
    John Kotuby, Dec 19, 2008
    #1
    1. Advertising

  2. John Kotuby

    John Kotuby Guest

    "John Kotuby" <> wrote in message
    news:%...
    > 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.
     
    John Kotuby, Dec 19, 2008
    #2
    1. Advertising

  3. John Kotuby

    bruce barker Guest

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

    -- buce (sqlwork.com)

    John Kotuby wrote:
    >
    > "John Kotuby" <> wrote in message
    > news:%...
    >> 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.
    >
     
    bruce barker, Dec 19, 2008
    #3
  4. John Kotuby

    John Kotuby Guest

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

    "bruce barker" <> wrote in message
    news:...
    > this is why you should use ScriptManger.RegisterStartupScript. it will
    > render the script after sys is defined.
    >
    > -- buce (sqlwork.com)
    >
    > John Kotuby wrote:
    >>
    >> "John Kotuby" <> wrote in message
    >> news:%...
    >>> 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.
    >>
     
    John Kotuby, Dec 22, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ronald Meier
    Replies:
    2
    Views:
    1,495
    Keith S.
    Oct 21, 2003
  2. Roman Neuhauser
    Replies:
    0
    Views:
    661
    Roman Neuhauser
    Apr 4, 2005
  3. Replies:
    2
    Views:
    654
    velle
    Jan 5, 2006
  4. John Salerno
    Replies:
    3
    Views:
    291
    John Salerno
    Mar 5, 2006
  5. gen_tricomi
    Replies:
    2
    Views:
    746
    gen_tricomi
    May 23, 2006
Loading...

Share This Page