Disabling Mouse clicks while processing using javascript

Disabling Mouse clicks while processing using Javascript

   We had an ASP.NET page and user can select something in dropdown and press Submit button and depending on that some data is displayed in datagrid.
   The issue is before even the data comes back the user selects some other value in dropdown and presses “Submit”, which we do not want.

We want to disable the mouse clicks of the user till the user gets the data for the first request.
   Basically I want two javascript functions – One for disabling the mouse clicks and another one for enabling it back.

Solution 1:

   In the OnBeforeUnload event disable/enable all the form controls using the  javascript….

for(var i=0; i<document.forms[0].elements.length; i++)
    {
       try
       {
          if(document.forms[0].elements[i].type + "" == 'hidden' ||  document.forms[0].elements[i].style.display=="none")
 
          continue;
 
          document.forms[0].elements[i].disabled = true;

        }

       catch(e)
       {}
    }


Solution 2  

Submit the form only when the button is clicked for the first time and don't submit it again when the form submission is in progress.

   This can be achieved using the code as below:

Server Side:

    btnSubmit.Attributes.Add("onclick","javascript:return submitForm();");

Client Side:

      //isFormSubmitted variable is used to prevent the form submission while the server execution is in progress
      var isFormSubmitted = false;

      //If the form is already submitted, this function will return false preventing the form submission again.

      function submitForm()
      {

            if(isFormSubmitted)
                  return false; 

            isFormSubmitted = true;
            return true;
      }

1 2

Close    To Top
  • Prev Article-Programming:
  • Next Article-Programming:
  • Now: Tutorial for Web and Software Design > Programming > dotnet > Programming Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction