I've tried using the solution at https://www.aspsnippets.com/Articles/Disable-ASPNet-button-after-click-to-prevent-double-clicking.aspx but it isn't working in my case. I believe the problem is that my button is in a panel that is by default not visible. Here's the Javascript code I'm using:
window.onbeforeunload = DisableSubmitButton(); function DisableSubmitButton() { var btn = document.getElementById('<%=btnSubmit.ClientID%>'); //make sure submit button was found (it may be in a panel that has Visible set to false). If found, disable it if (btn) { btn.disabled = true; } }
It isn't finding the button and disabling it when I click it. Any ideas?
Actually, I found a simpler way that doesn't require any Javascript functions nor code-behind changes:
<asp:Button ID="btnSave" runat="server" Text="Save" UseSubmitBehavior="false" OnClientClick="this.disabled='true';" </asp:button>
Works perfectly!
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.