tags:

views:

1155

answers:

3

I have a buttonfield in a gridview. When the button is clicked the RowCommand function gets called.

I need to pop up an alert box to make the user confirm their choice. I am pretty sure there is an HtmlInputButton involved but I kind of just need the syntax.

After that, how do you know whether they confirmed?

+1  A: 

You can find the button, via the ItemDataBound event and then add a confirmation box.

button1.Attributes.Add("OnCLick", "javascript: return confirm('Are You Sure You Want to Delete");")

That should get you what you need.

Mitchel Sellers
+3  A: 

In your aspx, put this on your button :

OnClientClick="javascript:return confirm('are you sure ?')"
mathieu
A: 

You can also use the ConfirmButtonExtender if you're using the Ajax Control Toolkit

If you're using jQuery (which I'd totally recommend) you should check out jQuery UI and the modal confirmation demo which is very slick.

It should be noted that the above confirmations are purely client-side, so if you need to support clients that have javascript turned off, you will need to handle all of this server-side as well. e.g. the javascript, when OK is clicked, could set a hidden form field that says the equivalent of 'user confirmed' so if you get the delete button pressed without the hidden form field being filled you can determine that you need to show a server-generated confirmation field.

Robert Paulson