Disable asp: Button after being clicked

3

Project in: WebForm, C #, ASP.net

I need to disable the button after it has been clicked. Today it looks like this:

<asp:Button ID="btn_Enviar" runat="server" CssClass="btn btn-primary" Text="Enviar" OnClick="btn_Salvar_Click" data-loading-text="Salvando..." Width="164px" />

I tried the call btn_Salvar_Click

btn_Enviar.enabled = false;

But it did not work. I tried calling a JavaScript to disable it and at best it disabled but did not submit.

How to do it?

Complementing : When the person clicks the button to save the form, the system takes a few seconds, causing the person to click again and another time, when I go to see the system registered several products! So I would like that when clicking once, the button is disabled, so I avoid multiple entries. If you can not do this I will have to make a logic to check if the product has already been registered.

    
asked by anonymous 22.08.2014 / 15:28

1 answer

2

The event of button_Click can not interfere with the behavior of the button, so it has to be another event to modify this button.

Place in the Page_Load of your Code Behind as follows:

btn_Enviar.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btn_Enviar, null) + ";");
    
22.08.2014 / 17:06