Give priority to a specific asynchronous postback

Source: Internet
Author: User
Tags visual studio

By default, when a page generates multiple asynchronous postbacks at the same time, the most recently generated postback takes precedence. In some cases, you can give priority to a specific asynchronous postback and cancel other postbacks.

Prerequisite

To implement these procedures in your own development environment, you need to:

Microsoft Visual Studio 2005 or Microsoft Visual Web Developer Express Edition.

An AJAX-enabled ASP.net web site.

Create a script to give priority to a particular postback element

First, create ECMAScript (JavaScript) code to manage asynchronous postbacks in the browser.

Create a script to give priority to a particular postback element

In the ASP.net web site, add a JScript file and name it postbackprecedence.js.

Add the following script to the file:

Sys.Application.add_load (Applicationloadhandler)
function Applicationloadhandler (sender, args)
{
if (! Sys.WebForms.PageRequestManager.getInstance (). Get_isinasyncpostback ())
{
Sys.WebForms.PageRequestManager.getInstance (). Add_initializerequest (initializerequest);
}
}

var Divelem = ' AlertDiv ';
var Messageelem = ' alertmessage ';
var exclusivepostbackelement = ' Button1 ';
var lastpostbackelement;
function initializerequest (sender, args)
{
var PRM = Sys.WebForms.PageRequestManager.getInstance ();
if (Prm.get_isinasyncpostback () &&
Args.get_postbackelement (). id = = exclusivepostbackelement)
{
if (lastpostbackelement = = exclusivepostbackelement)
{
Args.set_cancel (TRUE);
ActivateAlertDiv (' Visible ', ' A previous postback is still executing. The new postback has been canceled. ');
settimeout ("ActivateAlertDiv" (' Hidden ', ') ', 1500);
}
else if (lastpostbackelement!== exclusivepostbackelement)
{
Prm.abortpostback ();
}
}
else if (Prm.get_isinasyncpostback () &&
Args.get_postbackelement (). ID!== exclusivepostbackelement)
{
if (lastpostbackelement = = exclusivepostbackelement)
{
Args.set_cancel (TRUE);
ActivateAlertDiv (' Visible ', ' A previous postback is still executing. The new postback has been canceled. ');
settimeout ("ActivateAlertDiv" (' Hidden ', ') ', 1500);
}
}
Lastpostbackelement = Args.get_postbackelement (). ID;
}

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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.