0

Inside update panel I have 40 buttons: Button1, Button2, Button3 etc

On each button click, text will be stored to a variable as below:

protected void Button1_Click(object sender, EventArgs e)
    {
        string text1="You clicked button1";
    }

When I click on Button1 the ajax gif inside updateprocess will start but at the same time it allows other buttons to be clicked.

How do I prevent it?

Else is there any other way to do so other than using updateprocess?

5
  • Just like that Button2.Enabled = false;? Commented Jun 19, 2020 at 14:29
  • On button click..? If yes, after the Button1 is clicked and text is stored I want the rest of the buttons to be enabled. @SelimYıldız Commented Jun 19, 2020 at 14:34
  • Exactly, do you want to also set enable of all these buttons after click function is done, right? Commented Jun 19, 2020 at 14:49
  • Yes @SelimYıldız Commented Jun 19, 2020 at 14:55
  • Ok, it makes sense now. I have added an answer please check. Commented Jun 19, 2020 at 14:58

1 Answer 1

2

After discussion we had in comments, if I understood you correctly you can use OnClientClick to disable buttons when user clicked in client side. After click function is completed you can enable all of these buttons from server side.

Client side:

<script>
    function DisableButtons() {
        $("#<%=btn1.ClientID %>").attr('disabled', true);
        $("#<%=btn2.ClientID %>").attr('disabled', true);
        //other buttons
    }

</script>

<asp:Button ID="btn1" Text="Button 1" runat="server" OnClick="btn1_Click" OnClientClick="DisableButtons();"  UseSubmitBehavior="false" />
<asp:Button ID="btn2" Text="Button 2" runat="server" OnClick="btn2_Click" OnClientClick="DisableButtons();"  UseSubmitBehavior="false"  />
<%--Other buttons--%>

Note that you need to add UseSubmitBehavior="false" as well to buttons.

Server side:

protected void btn1_Click(object sender, EventArgs e)
{
    //other processes
    SetButtonsEnable();
}

protected void SetButtonsEnable()
{
    btn1.Attributes.Remove("disabled");
    btn2.Attributes.Remove("disabled");
    //other buttons
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.