'Sys.WebForms.PageRequestManager' is null or not an object
Asked Answered
F

3

4

Hi I have an aspx page in which i have the following code

  <asp:ScriptManager ID="scriptManager" runat="server" AsyncPostBackTimeout="500" EnablePageMethods="true">
            </asp:ScriptManager>

            <script type="text/javascript">
          Sys.Application.add_init(BeginRequestHandler);
          Sys.Application.add_init(EndRequestHandler);

          Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
          Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
          function BeginRequestHandler(sender, args) {
              AsynProcessing('block', 'AlertDiv', 'ProcessingImage');
          }
          function EndRequestHandler(sender, args) {
              AsynProcessing('none', 'AlertDiv', '');
          }
          function AsynProcessing(visstring, elem, img) {
              var adiv = $get(elem);
              adiv.style.display = visstring;
              adiv.image = img;
          }

But the page is throwing a javascrip error as 'Sys.WebForms.PageRequestManager' is null or not an object. I have placed the below the scriptmanager tag. I even ried adding

<xhtmlConformance  mode="Transitional"/>

in the section of web.config.But still getting the same error.
Any help is much appreciated. Thanks in advance

Featheredge answered 15/8, 2011 at 6:41 Comment(0)
C
5

Wrap your handlers with this code, in order to wait for all nessesary scripts were loaded, before calling Sys.WebForms.PageRequestManager

Sys.Application.add_init(function(){ ... your code ....}

http://msdn.microsoft.com/en-us/library/bb397532.aspx

EDIT:The reason of error at this line Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandl‌​er) is scripts havn't been loaded yet, so if you want handling of an asynchronous postback, you have to write something like this:

Sys.Application.add_init(function(){ 
    Sys.WebForms
       .PageRequestManager
       .getInstance()
       .add_beginRequest(BeginRequestHandler)
});

What does it mean in plain English? Wait until all scripts have been loaded (including Sys.WebForms namespace) and subscribe to event beginRequest You script block should be like this:

<script type="text/javascript">
    Sys.Application.add_init(function () {
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
    });
    Sys.Application.add_init(function () {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    });

    function BeginRequestHandler(sender, args) {
        AsynProcessing('block', 'AlertDiv', 'ProcessingImage');
    }
    function EndRequestHandler(sender, args) {
        AsynProcessing('none', 'AlertDiv', '');
    }
    function AsynProcessing(visstring, elem, img) {
         var adiv = $get(elem);
         adiv.style.display = visstring;
        adiv.image = img;
    }  
</script>
Calci answered 15/8, 2011 at 7:15 Comment(6)
Hi thanks.. i tried this...But when Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler); is executed, WebForms is 'undefined'. so again i am getting the same exceptionFeatheredge
Could you share more code, please? AsynProcessing method, and object which is forsing beginRequest handler. Thanks!Calci
Hi...I tried with the code given by you.but i am still getting the same error. In the aspx page, i have given Sys.Application.add_init(function () { Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler); });Featheredge
but in the dynamic page it is getting displayed as 'Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);' why is it so?Featheredge
I am sorry, I've lost your idea. What do you call dynamic page? Is it page which you see at the browser? Do I correctly understand you? You've written at aspx Sys.Application.add_init(function () { Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandl‌​er); }); but browser shows Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHand‌​ler); when you are doing viewsorceCalci
by dynamic page, i meant if we are dubugging in VS, the code of the aspx page that is being built will be shown,rite?Featheredge
G
2

It seems like your JavaScript block is executing before ASP.net Ajax has loaded, try placing this at the bottom on your page or after <form> tags...

Gramnegative answered 15/8, 2011 at 6:45 Comment(9)
Hi..Thanks for your reply. I am entirely new to aspx. So if i am asking some silly doubts, pls bear with me. In my page, i dont have a <form> tag. Do i have to place this inside </asp:Content> or outside it?Featheredge
where have you added <asp:ScriptManager>, in MasterPage or in aspx page? If in case you have added it in aspx page, than remove it from there and add it under <form> tag in your MasterPageGramnegative
can u tell me how to find out the master page for a particular aspx?Featheredge
In your aspx page inside <%@Page %> tag (on the very top of your aspx page), look for MasterPageFile property, it must be something like xyz.Master ...Gramnegative
Hi Waqas, i have placed it in the master page. But still getting the same error....Featheredge
you have placed <asp:ScriptManager> tag inside you masterpage after form and javascript block you pasted above, inside <asp:Conten> tags in your aspx page?Gramnegative
actually, i placed both tag and scripts in master page. Am i supposed to do the other way?Featheredge
no, place asp:ScriptManager after <form> tag inside masterpage and <javascript> block inside <asp:Content> in your aspx page, it shuld work themGramnegative
try using the suggestion of IceN, its pretty and I am sure it will workGramnegative
S
0

I had this problem as well. For me it was due to a web farm and missing machinekey entry in the web.config.

<system.web>
 <machineKey validationKey="D61B3C89CB33A2F1422FF158AFF7320E8DB8CB5CDA1742572A487D94018787EF42682B202B746511891C1BAF47F8D25C07F6C39A104696DB51F17C529AD3CABE"
   decryptionKey="FBF50941F22D6A3B229EA593F24C41203DA6837F1122EF17" />

Stockmon answered 12/6, 2012 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.