Justin Cooney

Web Development Tips and Examples

  • When using JavaScript on a ASP.NET Webforms page one can register the JavaScript function to execute using the OnClientClick attribute of the asp:button control. This can be quite usefu,l for example, when adding a script to stop duplicate submissions.

    However, it is important to correctly disable the button control since using the wrong command will cause the Webform to break. (more…)

  • To prevent forms from being submitted more than once I sometimes like to add a simple JavaScript function to the Submit button that disables the button when it is clicked. This does not provide a complete guarantee that the data is not sent twice, but it is effective at reducing the risk of multiple submissions.

    Specifically here is an example of the JavaScript function:

    <script language="javascript" type="text/javascript">
    function handleFormSubmit(){
    var btnInitiateProcess = document.getElementById('btnInitiateProcess');
    btnInitiateProcess.style.display = 'none';
    }
    </script>

    Then in the HTML of the submit button I add a call to the function as follows:

    <input type="submit" id="btnInitiateProcess" onClick="handleFormSubmit()">
  • Today I was working on a maintenance Web page that triggers a SQL Server stored procedure. This stored procedure can either run quite quickly, or it can take in excess of seven minutes to finish. So in order to let the user know that the process is executing in the background I added a small floating div to the page with a message encouraging patience that the code is still running and I disabled the submit button so the form could not be submitted more than once.

    The floating div/submit button disabling is triggered on click of the submit button using the OnClientClick attribute. However on the page I also have some RequiredFieldValidator and RegularExpressionValidator controls. (more…)