Disable <Asp:Button after being clicked

Asked

Viewed 2,742 times

4

Project in: Webform, C#, ASP.net

I need to disable the button after being clicked. Today it is 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 on the call btn_Salvar_Click

btn_Enviar.enabled = false;

But it didn’t work. I tried calling Javascript to disable and at best it disabled but didn’t post (Submit).

How to do?


Complementing: When the person clicks on the button to save the form, the system takes a few seconds, causing the person to click again and again, when I will see the system has registered several products! So I would like to click once, the button is disabled, so avoid multiple entries. If I can’t do it I’ll have to make a logic to check if the product has already been registered.

  • 1

    Strange that his ID is btn_Enviar and the Onclick event is btn_Salvar_Click, are you sure you’re sending it to the right event? Could put the event code btn_Salvar_Click?

  • yes...I can create the name I want, usually the name is created with the name of the button, but it can be anyone; This right the btn_Envir button calls btn_Salvar_Click, I tried to put a btn_Enviar.enabled=false; and nothing helps

1 answer

3


Is that the event of button_Click cannot interfere with button behavior, so it has to be another event to modify this button.

Put in the Page_Load of your Code Behind the following:

btn_Enviar.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btn_Enviar, null) + ";");
  • 1

    As always you were right Gypsy, unraveling the mysteries of Asp.net.. I put it within the condition: if (!Page.Ispostback){

  • Only a gypsy detail, when putting this code, worked, disabled the button, but a textbox stopped sending, started sending empty the field

  • This has nothing to do with the button. It’s something else from your Form.

  • Would you have any idea why she would give this conflict? I believe it is because this field is modified by the Ckeditor?

  • @Dorathoto I do not know. Just debugging to know.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.