How to display confirmation prompt for delete button?

Posted on 2013-10-15
Medium Priority
Last Modified: 2013-10-16
I recently saw a posting here that advised on how to set up a confirmation prompt for a delete button as such in the Page_Load() in my VB.NET web form:

btnDelete.Attributes.Add("onclick", "return confirm('are you sure wish to delete this record?');")

This works, but I wanted to be able to display the selected record in the prompt instead of a generic "are you sure you wish to delete this record".

Is this possible?
Question by:rascal

Expert Comment

by:Johny Bravo
ID: 39575903
This button is in Gridview or on page ?
LVL 20

Accepted Solution

Rikin Shah earned 2000 total points
ID: 39576800

You can concatenate the string with record Id/Name like below:

Updated with VB.Net code:

Dim data As String = "Record Name"
Button1.Attributes.Add("onclick", "return confirm('are you sure wish to delete " & data & " record?');")

Open in new window


Author Closing Comment

ID: 39577246
Thanks rikin_shah,

I put the code in the OnChange handler for my combobox:

Protected Sub ddlLoginList_SelectedIndexChanged(sender As Object, e As EventArgs)

        ' Get the selected value
        sSelectedIndex = ddlLoginList.SelectedValue

        btnDelete.Attributes.Add("onclick", "return confirm('are you sure you wish to delete this record? " & sSelectedIndex & "');")

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question