<asp:Button runat="server" ID="btnUserDelete" Text="Delete" CssClass="GreenLightButton" OnClick="BtnUserDelete_Click" OnClientClick="return UserDeleteConfirmation();" meta:resourcekey="BtnUserDeleteResource1" />
I have tried:
function UserDeleteConfirmation() { if (confirm("Are you sure you want to delete this user?")) return true; else return false; }
and
function UserDeleteConfirmation() { if (confirm("Are you sure you want to delete this user?")) { __doPostBack(btnUserDelete, ''); } return false; }
And none of them works.
Try this:
<asp:Button runat="server" ID="btnUserDelete" Text="Delete" CssClass="GreenLightButton" OnClick="BtnUserDelete_Click" OnClientClick="if ( ! UserDeleteConfirmation()) return false;" meta:resourcekey="BtnUserDeleteResource1" />
This way the "return" is only executed when the user clicks "cancel" and not when he clicks "ok".
By the way, you can shorten the UserDeleteConfirmation function to:
function UserDeleteConfirmation() { return confirm("Are you sure you want to delete this user?"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With