Disable common UpdateProgress controls for an UpdatePanel with an associated UpdateProgress

John Avis by | April 12, 2017 | ASP.NET Web Forms

If you have an ASP.NET Web Forms page with multiple UpdatePanels and multiple UpdateProgress controls, sometimes you may want one or more UpdateProgress controls associated with a specific UpdatePanel, and one or more UpdateProgress controls that have no association with an UpdatePanel so are shown when any UpdatePanel is updated.
If you have an ASP.NET Web Forms page with multiple UpdatePanels and multiple UpdateProgress controls, sometimes you may want one or more UpdateProgress controls associated with a specific UpdatePanel, and one or more UpdateProgress controls that have no association with an UpdatePanel so are shown when any UpdatePanel is updated.

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>

Related Posts

ASP.NET Web Forms Bootstrap

More on Bootstrap 4 modals in ASP.NET Web Forms applications using UpdatePanels

by John Avis | April 9, 2019

In this, my third post on this topic, I go over the methods I am using now and the problems I have encountered and overcome.


ASP.NET Web Forms Classic ASP

Custom error pages for ASP.NET Web Forms and Classic ASP in IIS 7 and 8.5

by John Avis | February 20, 2019

I was recently doing some work on a website which has a mixture of older Classic ASP pages and ASP.NET Web Forms pages and ran into problems with custom error pages.


ASP.NET Web Forms

Nicer localised UpdateProgress’ for your ASP.NET pages with multiple UpdatePanels

by John Avis | February 9, 2018

On an ASP.NET Web Forms page with multiple UpdatePanels it’s nice to give the user some feedback when one of the panels is being updated.

Comments

There are no comments yet. Be the first to leave a comment!

Leave a Comment
Tags
ASP.NET Html Forms ASP.NET MVC ASP.NET Web Forms ASP.NET Web Pages Bootstrap C# Classic ASP Cool Websites Databases eBay and PayPal Electrical Repairs General Hardware HTML/CSS Jquery/Javascript Media Center Mobile Phones Responsive Web Design SEO and Social Networking Web Design Web Development Web Security web+db Website Hosting Windows XP Youtube

About me

...mostly about web development and programming, with a little bit of anything else related to the Internet, computers and technology.

Subscribe

Get the latest posts delivered to your inbox.