How to display confirmation prompt for delete button?

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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Johny BravoCommented:
This button is in Gridview or on page ?
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rascalAuthor Commented:
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 & "');")
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.