How to disable a button once the form submitted?

advertisements

I am using asp.net webforms; I want to submit a form and keep the button disabled until it gets saved to my database, exactly like Stackoverflow. Any suggestion?

protected void Lb_Save_Click(object sender, EventArgs e)
{
   //disable my button
      //Do a DB insert
   //enable my button
}

EDIT:

I'll do a client-side validation first so I don't want my button to be disabled there but I want to disable it once the onclick function starts. Hope you all get my point.

Also i would like to do the same for asp:linkbutton but i don't know how firefox behaves for it. As the linkbutton will be rendered as anchor how can i disable it?

Guys you didn't get my question.

How to disable asp:button during postback? (not in jQuery/Javascript)


It disables it on submit(), it never enables it again because you're redirected. However, if you wanted to do some sort of validation you would just do

$("#yourForm").submit(function(e) {
    $("#yourButton").attr('disabled','disabled');
    if (whateverValidation) {
        e.preventDefault();
        $("#yourButton").removeAttr('disabled');
    }
});