header image
 

How to disable a button when clicked, before it starts an AJAX postback

    <script language=”javascript” 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
        if(pbControl.id.indexOf(‘saveButton’) > -1)
        {
            pbControl.disabled = true;
        }
    }

    function EndRequestHandler(sender, args) {
        if(pbControl.id.indexOf(‘saveButton’) > -1)
        {
            pbControl.disabled = false;
        }
        pbControl = null;
    }

    </script>

~ by shoel on October 29, 2008 .



Leave a Reply