locked
On web form button, prevent user from clicking the button more than 1 time RRS feed

  • Question

  • User-1997257017 posted

    In a vb.net 2010 web form application that uses web form controls, there is a 'process' button where the user can click on the button lots of times.
    This causes problems in the application for every time the button is clicked on, that many records are created in the sql server 2016 database.

    I would like a solution on how to prevent the user from clicking on the button more than one time. I have a 'click button' code to catch when the button is clixked right away.
    But I would like to know what I can do so the user knows they cannot click the button more than once:
    1. I could make the button invisible.
    2. However I would either like to have a popup message and/or somewhere on the webpage saying they can click on the process button only one time.
    Thus can you show me the code on preferable setting up a popup menu? If not, can you show me the code on how to display the message on the web form page?

    Thursday, January 17, 2019 4:05 PM

Answers

  • User36583972 posted


    Hi john_bal,

    For the following code, how do you know that the button will not show up for 2 hours? What in the code makes this happen?

    Referring to the following code:

          Type cstype = this.GetType();
               
    // Get a ClientScriptManager reference from the Page class.
               
    ClientScriptManager cs = Page.ClientScript;
               
    // Check to see if the startup script is already registered.
               
    if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
               
    {
                   
    String cstext = "alert('You can only click once in 2 hours');";
                    cs
    .RegisterStartupScript(cstype, "PopupScript", cstext, true);

    As I said above, you can check records in the database and compare with current time. This is a need you to implement a comparison logic yourself.

    Note: when everyone gives you some advice, please try it by yourself. If you have any question, you can include all necessary code snippets for anyone else to be able to reproduce your issue from scratch along with a detailed description about the results including any exception messages. This will help us quickly analyze your problem.

    If you have a new question you can start a new thread. Please don't ask several questions in the same thread.

    Best Regards,

    Yong Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 4:58 AM

All replies

  • User2103319870 posted

    . I could make the button invisible.

    You can hide the button on click like below

    <asp:Button ID="Button1" runat="server" Text="Click here" OnClientClick="this.style.display = 'none';"  />

    Thursday, January 17, 2019 7:56 PM
  • User36583972 posted

    Hi wendy,

    I would like a solution on how to prevent the user from clicking on the button more than one time.

    You want to prevent multiple clicks at the same time? or Click once in a time period?

    If you want to prevent multiple clicks at the same time, you can try the following way.

    prevent click after the server has finished processing.

     Button14.Attributes.Add("onclick", "this.value='processing ,please wait……';this.disabled=true;" + this.GetPostBackEventReference(Button14) + ";");
    

    Or you want click once in a time period. You can check records in the database and compare with current time. Then, give a tip through Popup.

                Type cstype = this.GetType();
                // Get a ClientScriptManager reference from the Page class.
                ClientScriptManager cs = Page.ClientScript;
                // Check to see if the startup script is already registered.
                if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
                {
                    String cstext = "alert('You can only click once in 2 hours');";
                    cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
                }
    

    Best Regards,

    Yong Lu

    Friday, January 18, 2019 8:31 AM
  • User-1997257017 posted

    For the code above, the button would just disappear?

    Tuesday, January 22, 2019 4:22 AM
  • User-1997257017 posted

    For the following code, how do you know that the button will not show up for 2 hours? What in the code makes this happen?

    Referring to the following code:

          Type cstype = this.GetType();
               
    // Get a ClientScriptManager reference from the Page class.
               
    ClientScriptManager cs = Page.ClientScript;
               
    // Check to see if the startup script is already registered.
               
    if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
               
    {
                   
    String cstext = "alert('You can only click once in 2 hours');";
                    cs
    .RegisterStartupScript(cstype, "PopupScript", cstext, true);

    Tuesday, January 22, 2019 4:24 AM
  • User36583972 posted


    Hi john_bal,

    For the following code, how do you know that the button will not show up for 2 hours? What in the code makes this happen?

    Referring to the following code:

          Type cstype = this.GetType();
               
    // Get a ClientScriptManager reference from the Page class.
               
    ClientScriptManager cs = Page.ClientScript;
               
    // Check to see if the startup script is already registered.
               
    if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
               
    {
                   
    String cstext = "alert('You can only click once in 2 hours');";
                    cs
    .RegisterStartupScript(cstype, "PopupScript", cstext, true);

    As I said above, you can check records in the database and compare with current time. This is a need you to implement a comparison logic yourself.

    Note: when everyone gives you some advice, please try it by yourself. If you have any question, you can include all necessary code snippets for anyone else to be able to reproduce your issue from scratch along with a detailed description about the results including any exception messages. This will help us quickly analyze your problem.

    If you have a new question you can start a new thread. Please don't ask several questions in the same thread.

    Best Regards,

    Yong Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 4:58 AM