ASP - Disable a button to prevent user from clicking twice [Answered]RSS

1 reply

Last post Jan 22, 2014 02:49 AM by Angie xu - MSFT

  • ASP - Disable a button to prevent user from clicking twice

    Jan 21, 2014 07:43 AM|ashok.k|LINK

    Hi,

    I am working on an ASP website. I want to disable a button after the user clicks the button.

    If the users click the button twice by mistake, the DetailsPage.ASP is executed twice and duplicate entries are inserted into Database.

    How to disable a button in ASP code to prevent the users from clicking twice?

    Page1: Mainpage.asp page
    <form action="DetailsPage.asp" method="POST">
    <input type="Submit" name="Submitbutton" value="Update Details">

    How to prevent the users from clicking the button twice or alert them if they try to click second time?

    Another other suggestions to handle this type of scenario will be helpful.

    Thanks in advance.

    Thanks
    Ashok

  • Re: ASP - Disable a button to prevent user from clicking twice

    Jan 22, 2014 02:49 AM|Angie xu - MSFT|LINK

    Hi

    According to your description above, you want to disable button to prevent double click in ASP, 

    Code in page(.aspx):

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script language="javascript" type="text/javascript">
            var submit = 0;
            function CheckIsRepeat() {
                if (++submit > 1) {
                    alert('An attempt was made to submit this form more than once; this extra attempt will be ignored.');
                    return false;
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" OnClientClick="return CheckIsRepeat();" />
        </div>
        </form>
    </body>
    </html>

    For further information: Disable a button to avoid double clicks- http://forums.asp.net/t/1681765.aspx

    Best regards

    Angie

    Angie xu

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.