Disable search button while waiting for AJAX response.

Last post 05-05-2008 3:55 PM by vikrant.soni. 5 replies.

Sort Posts:

  • Disable search button while waiting for AJAX response.

    05-11-2007, 2:18 PM
    • Member
      18 point Member
    • hughy
    • Member since 11-18-2006, 6:03 AM
    • Posts 22

    I have a GridView that gets populated/updated via an AJAX call. I'd like to disable the search button that executes the search while the AJAX call is executing. I've added a progress indicator (which is really cool and simple to implement) but I'd like to disable the search button while waiting for the AJAX call to prevent users from clicking the button again while the search is executing. I've tried simply disabling the button in the click event that is linked to my UpdatePanel trigger, registering script blocks to disable the button via javascript, disable the button via the OnClientClick attribute of the search button (this bombs ajax completely). I've tried placing the button within my update panel and outside the update panel and that doesn't seem to make a difference. Any ideas?

  • Re: Disable search button while waiting for AJAX response.

    05-16-2007, 10:33 AM
    Answer
    • Member
      18 point Member
    • hughy
    • Member since 11-18-2006, 6:03 AM
    • Posts 22

    I did a lot of searching and found 3 or 4 different ways of doing this but the one below was far and away my favorite. Basically, you can just attach a javascript method to the beginRequest and endRequest of the AJAX call.

    <script type="text/javascript">

    //add event handlers to the search UpdatePanel

    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest( startRequest );

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest( endRequest );

    function startRequest( sender, e ) {

    //hide the update panel during the AJAX call

    document.getElementById('<%=upSearchResults.ClientID%>').style.display = 'none';

    //disable search button during the AJAX call

    document.getElementById('<%=cmdSearch.ClientID%>').disabled = true;

    }

     

    function endRequest( sender, e ) {

    //show the update panel once the AJAX call has completed

    document.getElementById('<%=upSearchResults.ClientID%>').style.display = '';

    //re-enable the search button once the AJAX call has completed

    document.getElementById('<%=cmdSearch.ClientID%>').disabled = false;

    }

    </script>

     

  • Re: Disable search button while waiting for AJAX response.

    04-04-2008, 1:44 PM
    • Member
      91 point Member
    • brendalisa
    • Member since 11-29-2006, 4:02 PM
    • Posts 40

     Gosh, that works perfectly! Thanks!!!

     

    Brenda
  • Re: Disable search button while waiting for AJAX response.

    04-10-2008, 11:45 AM
    • Member
      2 point Member
    • snackpack15
    • Member since 04-10-2008, 3:43 PM
    • Posts 1

    hughy,

     What are the other methods you have found?? (Preferrably not using 3.5 framework.)

  • Re: Disable search button while waiting for AJAX response.

    04-11-2008, 3:28 PM
    • Member
      179 point Member
    • rhogan
    • Member since 06-27-2002, 1:50 PM
    • Deerfield, NH
    • Posts 63

    What if you have multiple update panels on the page and also master pages? Any way of disabling the buttons?

    "If you pick up a starving dog and
    make him prosperous, he will not bite you;
    that is the principal difference
    between a dog and a man."
    -- Mark Twain
  • Re: Disable search button while waiting for AJAX response.

    05-05-2008, 3:55 PM
    • Member
      15 point Member
    • vikrant.soni
    • Member since 11-19-2007, 7:36 AM
    • Mumbai
    • Posts 50

    in Above code I am getting javascript error message "Sys is undefined"

Page 1 of 1 (6 items)