disable double Click on Web Page

Hi Friend ,.
    Some time we face a problem like when we click on the server side button twice or more time ,it call a button event more then one time for single calling .some time it makes problem in our logic .so we need a solution code which hold the page till the server respond the single request .
Here i am placing a code which is useful in this case.

<script type="text/javascript">
        function pageLoad(sender, args) {
            var rm = Sys.WebForms.PageRequestManager.getInstance();
            rm.add_initializeRequest(initializeRequest);
            rm.add_endRequest(endRequest);
        }
        function initializeRequest(sender, args) {
            //Disable button to prevent double submit
            var btn = $get(args._postBackElement.id);
            if (btn) {
                btn.disabled = true;
                if (btn.className == 'button')
                    btn.className = 'buttonDisabled';
            }
        }
        function endRequest(sender, args) {
            //Re-enable button

            var btn = $get(sender._postBackSettings.sourceElement.id);
            if (btn) {
                btn.disabled = false;
                if (btn.className == 'buttonDisabled')
                    btn.className = 'button';
            }
        }
</script>
Hope this will help you

Rajesh

0 comments: