Disable button during javascript processing c#

Asked

Viewed 643 times

0

I have the following Asp button:

<asp:Button ID="btnOk" runat="server" AutoPostBack="true" CausesValidation="true" ClientIDMode="Static"  Text="Ok" Width="80px" OnClick="btnOk_Click" OnClientClick="btnOk_OnClick();return true;" class="dxbButton_Glass dxbButtonHover_Glass"></asp:Button>

And the following script:

function btnOk_OnClick() {
    $("#btnOk").prop("disabled", true);
}

The event on the server:

    protected void btnOk_Click(object sender, EventArgs e)
    {
         new Processar();
         ((Button)sender).Enabled = true;
    }

The idea here is that the button is disabled since processing it takes time, but when I disable the button in java script, the button click does not post, so the btnOk_Click event does not run.

Do you have a solution? Thank you.

2 answers

2

Remove client event from button (OnClientClick)

And use this line when loading the page:

window.onbeforeunload = btnOk_OnClick;
  • who denied the answer could at least have the education to explain the reason.

  • I said no, Ricardo. For the simple reason of the loss of navigability - or the unnecessary use of resources. You will force the button to be disabled even when the user changes pages, for example. It might work, but I couldn’t find a good solution and I was negative.. But I am not the owner of the truth, what matters is the friend Gabriel Reis have the problem solved. EDIT: I’ll take the negative.. I think that the answers should not be judged by opinions, but by functionalities. As it solves the problem in question, I will remove the -1.

  • No problem the negative, I just think I missed explain, for if you have any problem try not to repeat. Thank you.

0

A solution with jQuery:

1- I removed the OnClientClick:

<asp:Button ID="btnOk" runat="server" AutoPostBack="true" CausesValidation="true" ClientIDMode="Static" Text="Ok" Width="80px" OnClick="btnOk_Click" class="dxbButton_Glass dxbButtonHover_Glass"></asp:Button>

2- I created a capture event when submitting your form:

$("#id_do_seu_form").submit(function() {
    //desabilita o botão
    $("#btnOk").prop("disabled", true);
});

Browser other questions tagged

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