﻿// This code implements a precedence system for asynchronous postbacks
// It is based on the MSDN article at http://msdn.microsoft.com/en-us/library/bb386456.aspx

Sys.Application.add_load(ApplicationLoadHandler)
function ApplicationLoadHandler(sender, args) {
    if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
        Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);
    }
}

var lastPostBackElement;

function InitializeRequest(sender, args) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    // only worry if we're already in an async postback
    if (prm.get_isInAsyncPostBack()) {
//        if (args.get_postBackElement().id === lastPostBackElement) {
//            alert('The server is still processing the previous operation. Wait for this to complete and try again.');
//        }
        args.set_cancel(true);
    }
    lastPostBackElement = args.get_postBackElement().id;
}

if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
