2

Is there a way to determine from JavaScript if a page contains a scriptmanager, an updatepanel or if the __doPostBack is called from an update panel or is a partialpostback?

3 Answers 3

3

When one update panel is called, then there are two functions that trigger from javascript side. Inside this functions you can also get the Ids of the panel that trigger this update. If there is a full post back outside of an update panel, then you need to capture the submit of the form.

Here are the code that triggered when an update panel is going to upadte, together with the functions that show the update panel ids that make the trigger.

<script>

    if(window.Sys && Sys.WebForms && Sys.WebForms.PageRequestManager)
    {
      var prm = Sys.WebForms.PageRequestManager.getInstance();

       prm.add_initializeRequest(InitializeRequest);
       prm.add_endRequest(EndRequest);
    }
    else
    {
      // no ScriptManager found
    }        

      function InitializeRequest(sender, args) 
      {     
         // get the array of update panels id
         var UpdPanelsIds = args.get_updatePanelsToUpdate();
         // get the Post ID
         args.get_postBackElement().id;
      }

      function EndRequest(sender, args) {
      }
</script>

'Dan Davies Brackett' Correct describe how you can know if the ScriptManager exist.

Sign up to request clarification or add additional context in comments.

10 Comments

I still have a problem.. I can't tell if the request is an asyncpostback. The get_isInAsyncPostBack() is useless to me since it's not yet initialized in the InitializeRequest.
@user627283 If the InitializeRequest is called then is AsyncPostBack !
@user627283 can you give me the full image for what you try to do ? maybe I can help more
Little complicated.. i want to display a gray box over the page preventing the user from clicking multiple times on buttons on a submit. But if it's from an update panel, the gray box stays there because the page doesn't refresh. So i want to catch whatever the postback is from a __dopostback or a form.submit then determine if its a full postback, if it is, then display the gray box.
I don't want to display the gray box on partial postback because it "flickers".
|
1

If I understand correctly, there are two questions here:

(1) how do I tell in JavaScript whether a ScriptManager exists on a page?

If the server-side page contains a ScriptManager, there will be a PageRequestManager available on the client. You can discover whether it exists with:

 var haveScriptManager = window.Sys && Sys.WebForms && Sys.WebForms.PageRequestManager;

(2) how do I tell whether __doPostBack is synchronous?

Once you have a handle to the local PageRequestManager, you can hook the event that fires before every postback and check whether it's synchronous or asynchronous. Again, the documentation for the PageRequestManager will give you all the details of how to do that.

2 Comments

Thanks a lot! Didn't know about the PageRequestManager awesome!
+1 from me because the user... change his opinion, but this is a correct answer to the (1) part.
0

Emit the scriptManager clientID to some clientside javascript, then look for it on the page (document.getElementById(emittedClientID)

You can rename __doPostBack with... __NewDoPostBack = __doPostBack, then create a new function such as...

__doPostBack = function(whatever arguments __NewDoPostBack takes){
    alert("We're doing a post back");
    __NewDoPostBack(whatever arguments __NewDoPostBack takes)
}

2 Comments

who not use the PageRequestManager? that's what it's for.
This was a response to the question as it was originally written.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.