I need to add a confirmation popup to my asp:button
named "Delete". The popup should have options "Yes" and "No". If the user clicks on "Yes", I want to delete a record from a SQL database. If the user clicks on "No", nothing should happen.
<asp:Button runat="server" ID="btnDelete" Text="Delete"
OnClientClick="if(confirm('Delete?'))alert('You chose yes!');else alert('You chose no!')"
OnClick="btnDelete_Click" />
The btnDelete_Click
function contains SQL deletion logic.
However, I am facing an issue where the OnClick
method always executes, even if I select "No" in the JavaScript popup. It seems to trigger a postback regardless of the selection made.
Is there a way to pass the result of "Yes" or "No" to my code behind so that I can use a simple "if" statement for the deletion logic?