Disable button during javascript processing c #

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 the processing takes, but when I disable the button in the java script, the button click does not post, so the btnOk_Click event does not execute.

Do you have a solution? Thank you.

    
asked by anonymous 30.01.2017 / 16:49

2 answers

2

Remove the client event from the button ( OnClientClick )

And use this line when loading the page:

window.onbeforeunload = btnOk_OnClick;
    
30.01.2017 / 16:54
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 catch event when submitting your form:

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