'Check if page uses asp.net ajax from JavaScript
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?
Solution 1:[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.
Solution 2:[2]
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)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dan Davies Brackett |
| Solution 2 | MushinNoShin |
