0

I have an ASP.NET button that takes 1-2 seconds of server side processing. To prevent multiple clicks, I disable the button like below:

<asp:Button Text="Click Me" runat="server" ID="btnClickMe" OnClick="btnClickMe_Click" UseSubmitBehavior="false" OnClientClick="this.disabled = true;" />

protected btnClickMe_Click(object sender, EventArgs e)
{
    Thread.Sleep(2000); // Simulate work
    Response.Redirect("AnotherPage.aspx");
}

How can I re-enable the button when the user clicks the browser's back button?

I tried setting the button enable to true in the Page_Load event but that didn't work.

Adam Milecki
  • 1,738
  • 10
  • 15
  • http://stackoverflow.com/questions/22481553/refresh-page-on-back-click-mvc-4 – Greg Sep 17 '15 at 20:44
  • I'm using ASP.NET web forms application, not MVC, and I don't want to use JavaScript window.onunload because of other page features. Any other suggestions? – Adam Milecki Sep 17 '15 at 20:54
  • I did a quick test and I cannot seem to reproduce your issue. Which browser are you using? – Yacoub Massad Sep 17 '15 at 20:56
  • The latest Firefox. I forgot to mention that after I run the server-side code, I perform a Response.Redirect to another page in the application. – Adam Milecki Sep 17 '15 at 23:54

1 Answers1

0

This worked for me. I added this at the beginning of a JavaScript function:

$("#btnClickMe").attr("disabled", "disabled");

And this is on success or error of my ajax call:

$("#btnClickMe").removeAttr("disabled");
tcrite
  • 523
  • 2
  • 12
  • I haven't tried it but I believe this will only work if I was running purely client-side code, for which case I would accept it as the answer. However, my button click event is processed on the server-side. – Adam Milecki Sep 18 '15 at 13:44
  • I don't know if you're using Ajax or not, but I'm setting the disabled attribute at the beginning of the JavaScript function, and then removing it on success or failure of my Ajax call. I'm updating my answer to reflect that. – tcrite Sep 18 '15 at 19:22