When deleting an item from an ASP.NET grid, it would be nice to ask the user to confirm this is what they really meant to do. After all, it is very easy to mouse click somewhere by accident. And, what would even be nicer is if this confirmation takes place on the client (browser) instead of requiring yet another round trip to the server.
OnClientClick property, which is available with many ASP.NET controls.
Listing 1 shows part of the ASP.NET code for a
GridView control. This code includes an
<asp:GridView ID="GridView1" runat="server" />
<asp:LinkButton ID="lnkDelete" runat="server"
CommandArgument='<%# Bind("ItemID") %>'
OnClientClick="return confirm('Delete this item?');">
confirm(), which returns
true if the user selects Yes. The code associated with posting back the form and deleting the item only executes if this script returns