0
votes

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?

1
Just like that Button2.Enabled = false;?Selim Yildiz
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ızMEGHA POOJARY
Exactly, do you want to also set enable of all these buttons after click function is done, right?Selim Yildiz
Yes @SelimYıldızMEGHA POOJARY
Ok, it makes sense now. I have added an answer please check.Selim Yildiz

1 Answers

1
votes

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
}