Andreas Strandfelt
Andreas Strandfelt

Reputation: 98

Javascript confirm before running the eventhandler, which deletes records from the database

I have button, which fires an event, that deletes a record from the database. This is the source of the button:

<asp:Button ID="btnDelete" runat="server" Text="Delete" onclick="btnDelete_Click" />

But how can I make a confirm box appear before the deletion?

Upvotes: 0

Views: 505

Answers (1)

M4N
M4N

Reputation: 96576

Use the button's OnClientClick property:

<asp:Button ID="btnDelete" runat="server" OnClientClick="confirmDelete" ... >

<script type="text/javascript">
function confirmDelete()
{
  return confirm('Really delete this record?');
}
</script>

Upvotes: 1

Related Questions