views:

81

answers:

3

How might I add a JavaScript message box with a confirmation option in ASP.NET?

A: 

Use Javascript's confirm() method.

if(confirm('Are you sure?')) {
 // executed if the user clicks OK
}
Cody Caughlan
+2  A: 

Try using confirm :

<script>
    var userWantsToContinue = confirm("do you want to continue ?");
</script>
Canavar
A: 

If you are needing to add a confirm dialog box when the user clicks a button (such as a Delete button), where clicking Cancel has the effect of canceling a postback, you can use the Button control's OnClientClick property like so:

OnClientClick="return confirm('This will permanently delete this item. Are you sure you want to do this?');"

For more information on working with client-side script in an ASP.NET WebForms application, check out: Client-Side Enhancements in ASP.NET.

Scott Mitchell