ASP.Net Ajax避免使用者連續點按導致重覆觸發Async post back的簡單解法

ASP.Net Ajax避免使用者連續點按導致重覆觸發Async post back的簡單解法

避免自己忘記,做個筆記。

出處:http://www.dotnettechy.com/problem-solutions/avoid-double-click-on-button-inside-updatepanel-2.aspx

After the ScriptManager put follow script on the page

<script type="text/javascript">
    var pbControl = null;
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(BeginRequestHandler);
    prm.add_endRequest(EndRequestHandler);

    function BeginRequestHandler(sender, args) {
        pbControl = args.get_postBackElement(); //the control causing the postback
        pbControl.disabled = true;
    }

    function EndRequestHandler(sender, args) {
        pbControl.disabled = false;
        pbControl = null;
    }
</script>