Friday, January 17, 2014

.net javascript disabling buttons to show something is happening when button is selected

 I have some code I use when I want to give some visual clues to the user when a button is pressed on a .net web screen.

    Set up the onbeforeunload option to call the 'disableButtons()' function. It will disable the buttons after the action has been initiated, yet cause the appropriate code to execute in the code behind.  If you disable a button prior to the onbeforeunload event, then the code behind will NOT receive that the button has been clicked event, because it was disabled before evoking that event.


[code]
<body class="formStyle"  onbeforeunload="disableButtons();">


        var ButtonsToDisable = [];

        function validateUserSelections(vButton)
        {

            var btnCSV = document.getElementById("btnCSV");
            var btnSearch = document.getElementById("btnSearch");

            ButtonsToDisable.push(btnCSV);
            ButtonsToDisable.push(document.getElementById("btnSearch"));
           
            if (typeof vButton === 'undefined')
            {
                return true;
            }
            if (vButton == null)
            {
                return true;
            }

            if (vButton == 'CSV')
            {
                btnCSV.innerText = "Working";
            }
            return true;
        }

[/code]

No comments:

Post a Comment