Thursday 23 October 2008

Add a confirm popup in asp .net

To add a confirm popup when a button is clicked in asp .net do the following:

In the buttons OnClientClick add the following javascript:

if(confirm('Are you sure?'))
{
return true;
}else{
return false;
}

The confirm method returns a boolean.

The popup displays the message, an Ok button and a canel button.

If Ok is clicked return true allows the button to cause a post back.
Clicking cancel returns false cancel the submit action of the button.

1 comment:

Donald said...

Couldn't you just use

return confirm('Are you sure?');

Free Hit Counter