Add delete confirmation to asp.net ListView control

The ASP.Net ListView control is a godsend for developers.  Drop the control on the form, hook in a datasource, and you have complete, out-of-the-box view, edit, insert, and delete functionality.  One thing missing though is a delete confirmation if the user clicks the delete button.  The Delete button is right next to the Edit button so it’s fairly easy to mistakenly click it and with an accidental click, the record is permanently deleted with no prompt or warning issued to the user.

Adding a delete confirmation prompt is very simple to do.  Using the JavaScript confirm() function, we can add one line to the control definition and implement the delete confirmation dialog box.  Simply add a OnClientClick() call to the button control(s) in the ListView definitions (see the bold text in the example below).

<asp:Button ID=”DeleteButton” runat=”server” CommandName=”Delete” Text=”Delete” OnClientClick=”return confirm(‘Are you certain you want to delete?’);”/>

The result will be the pop of a delete confirmation dialog box as seen in the screenshot below.  Clicking the delete button pops the dialog.  If the user clicks the Cancel button then the dialog closes and no action is taken on the record.  Conversely, if the OK button is clicked then the dialog closes and the record deletion continues.

 

image

Leave a Reply

Related Post

Remotely monitoring your children’s computers using iTalc

Using iTalc on your private home network, you can monitor your kid’s activities and keep an eye on what websites they are browsing, what they are doing on social networking sites like Facebook, and even watch as they read their email. There are other tools that offer similar functions such as keylogging tools and web site blockers, but iTalc is a perfect addition to your arsenal of child protection tools.

Oracle DBA Notes

Useful Oracle DBMS Tips and Tricks CHECKING WORKSPACE ALLOCATION On DW’s NT box, click on the svmgr button on the toolbar. Log in as SYSTEM. Click Storage and the Tablespace tab. The percentages are shown for date files (name ends with a ‘D’) or index files (name ends with a ‘X’). GRANTING RIGHTS TO DBA […]

Security and Hacking Notes

Encryption and Authentication DESCRIPTION Privacy protection using DES (symmetric algorithm) involves the use of two secret keys. Each party must share their secret key with others. This makes this sort of encryption difficult to use in web technologies. RSA public key encryption (asymmetric) solves this problem. RSA uses matched pairs of encryption and decryption keys. […]