However, to me it makes sense that if an UpdatePanel has an associated UpdateProgress control, then any other UpdateProgress controls should not be displayed.
Unfortunately this is not how it works in ASP.NET. All unassociated UpdateProgress controls will be displayed, even if there is an associated UpdateProgress.
If you want to override how it works by default, and instead not display UpdateProgress controls if an UpdateProgress control exists that is associated with the UpdatePanel that triggered the update, then the following client-side script can be used.
The script should be placed or included after the ASP.NET ScriptResource.axd files are included. It's safe to place or include this script after the closing ASP.NET tag.
Note that this script will not function if a partial post back is triggered by a control outside of any UpdatePanel. You could modify the script to accommodate this if needed.
<script type="text/javascript">
//array of original values
var updateProgressDefaults = [];
Sys.Application.add_init(appl_init);
function appl_init() {
var c = Sys.Application.getComponents();
for (var i = 0; i < c.length; i++) {
if (Object.getType(c[i]).getName() == "Sys.UI._UpdateProgress" && !c[i]._associatedUpdatePanelId) {
updateProgressDefaults[c[i].get_id()] = c[i]._associatedUpdatePanelId;
};
}
var pgRegMgr = Sys.WebForms.PageRequestManager.getInstance();
pgRegMgr.add_initializeRequest(BeginHandler);
pgRegMgr.add_endRequest(EndHandler);
}
function BeginHandler(sender, args) {
//There is no _updatePanelsToUpdate if a trigger is outside of an UpdatePanel
if (!args._updatePanelsToUpdate) return;
//Check if the affected UpdatePanel has an associated UpdateProgress control
var hasUpdateProgress = false;
var c = Sys.Application.getComponents();
for (var i = 0; i < args._updatePanelsToUpdate.length; i++) {
for (var j = 0; j < c.length; j++) {
if (Object.getType(c[j]).getName() == "Sys.UI._UpdateProgress" && args._updatePanelsToUpdate[i].replace(/$/g, "_") == c[j]._associatedUpdatePanelId) {
hasUpdateProgress = true;
break;
}
}
if (hasUpdateProgress) break;
}
//If the UpdatePanel has an associated UpdateProgress control then set all the UpdateProgress controls without associated UpdatePanels to a non-existant UpdatePanel
if (hasUpdateProgress) {
for (var i = 0; i < c.length; i++) {
var id = c[i].get_id();
var type = Object.getType(c[i]).getName();
if (type == "Sys.UI._UpdateProgress" && !c[i]._associatedUpdatePanelId) {
c[i]._associatedUpdatePanelId = "NullUpdateProgress";
};
}
}
}
//Restores AssociatedUpdatePanelId for all UpdateProgress controls
function EndHandler() {
for (var key in updateProgressDefaults) {
$get(key).control._associatedUpdatePanelId = updateProgressDefaults[key];
}
}
</script>
Rate this post:
Comments
There are no comments yet. Be the first to leave a comment!