﻿
//registers the event by adding it to the endrequests collections of the instance
//This will allow it to actually listen to the event when it happens, and execute 
//the code in the onEndRequest function
function pageLoad() {
    Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(onEndRequest); //>>Key line of code for the correction
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onEndRequest);
}

//function which will execute after the C# code gets to its end
//it will then catch the exception and display it on the alert message box
//the substring is just to avoid having the full exception definition, 
//and display only the message
function onEndRequest(sender, args) {
    if (args.get_error() != null) {
        var msg = args.get_error().message;
        //alert(msg.substring(msg.indexOf(":", 0) + 1));
        alert(msg);
        args.set_errorHandled(true);
        onUpdated();
        return false;
    }
    else
    { return false; }
}
function onUpdating() {
    //alert(obja.id);
    //var updateProgressDivId;
    //var updatePanelId;
    // 取得顯示訊息的Div        
    var updateProgressDiv = $get('searchUpdateProgressDiv');
    //  取得GridView
    //var gridView = $get(updatePanelId);
    // 顯示查詢訊息
    updateProgressDiv.style.display = '';
//    // 計算GridView及訊息Div的位置 
//    var gridViewBounds = Sys.UI.DomElement.getBounds(parent);
//    var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);
//    var x;
//    var y;
//    x = gridViewBounds.x + Math.round(gridViewBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
//    y = gridViewBounds.y + Math.round(gridViewBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);
//    //    設定訊息顯示的位置 \n" +
//    Sys.UI.DomElement.setLocation(updateProgressDiv, x, y);
}
function onUpdated() {
    //var updateProgressDivId;
    // 取得顯示訊息的Div \n" +
    var updateProgressDiv = $get('searchUpdateProgressDiv');
    // 設定隱藏  \n" +
    updateProgressDiv.style.display = 'none';
}

