If you want to prevent the refresh of the UpdatePanel
, you can utilize code snippets similar to this example.
var divElem = 'AlertDiv';
var messageElem = 'AlertMessage';
Sys.Application.add_load(ApplicationLoadHandler)
function ApplicationLoadHandler(sender, args)
{
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CheckStatus);
}
function CheckStatus(sender, args)
{
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm.get_isInAsyncPostBack() & args.get_postBackElement().id == 'CancelRefresh') {
prm.abortPostBack();
}
else if (prm.get_isInAsyncPostBack() & args.get_postBackElement().id == 'RefreshButton') {
args.set_cancel(true);
ActivateAlertDiv('visible', 'Still working on previous request.');
}
else if (!prm.get_isInAsyncPostBack() & args.get_postBackElement().id == 'RefreshButton') {
ActivateAlertDiv('visible', 'Retrieving headlines.');
}
}
function ActivateAlertDiv(visString, msg)
{
var adiv = $get(divElem);
var aspan = $get(messageElem);
adiv.style.visibility = visString;
aspan.innerHTML = msg;
}
if(typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
Nevertheless, the ASP.NET request processing will proceed in the background.
In case the user is unable to navigate until this process concludes, it might be due to ASP.NET session locking which prevents the second request from starting until the first one finishes. To address this, you could consider inspecting the Response.IsClientConnected property within your initial request's code and terminate it if false
. This check may need to be performed in a separate thread if the main thread is occupied with processing tasks, depending on your application's setup.
An alternative approach would be to disable session usage or set it to read-only if your page doesn't require writing data to it (as suggested in this response):
If your page does not modify any session variables, you can opt out of most of this lock.
<% @Page EnableSessionState="ReadOnly" %>
If your page does not read any session variables, you can opt out of this lock entirely, for that page.
<% @Page EnableSessionState="False" %>
If none of your pages use session variables, just turn off session state in the web.config
<sessionState mode="Off" />