Results 1 to 4 of 4

Thread: Disable ASPX Submit button after click

  1. #1

    Thread Starter
    Lively Member tgoodmannz's Avatar
    Join Date
    Sep 2000
    Location
    Mid On at the Pavillion End
    Posts
    102

    Disable ASPX Submit button after click

    Hi,

    I have an ASPX submit button


    The processing behind the click event takes a small amount of time - I want to disable the button on the client side so that the button cannot be clicked again until processing has finished ...

    I've seen a few blogs on this but non of them seem to work ..

    Any ideas?

    Cheers,
    Tim

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Instead of using the submit button directly, make it non-visible.

    Then, place another non-runat-server button on the page with your own onClick event handler.

    In that event handler, spoof the event handler for your now-hidden button.

    It usually looks something like:

    __doPostback("buttonName")

    You can find it by looking at your source code.

    If this button is the default submit button for the form, then instead of doing that, just submit the form in your event handler:

    Form1.submit();
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  3. #3
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    And the part I forgot to mention:

    When you take care of posting the form in your custom event handler, make sure to disable the other button...
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  4. #4

    Thread Starter
    Lively Member tgoodmannz's Avatar
    Join Date
    Sep 2000
    Location
    Mid On at the Pavillion End
    Posts
    102
    Thanks LR - that worked a treat...

    Code:
     
    
    <script language="javascript">
    	function ufSaveButtonClick() {			    
                       document.getElementById('btnOK').disabled=true; 
                       __doPostBack('cmdOK','');			
    	}
    
    </script>
    
    .....
    
    
        <BUTTON id="btnOK" style="FONT-SIZE: x-small; WIDTH: 65px" onclick="ufSaveButtonClick();type="button">OK</BUTTON>
        <asp:button id="cmdOK" runat="server" Width="65" Text="OK" Visible="False"></asp:button></CENTER>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width