You have a standard button server control. This button is rendered in the HTML as a standard form submit button.
You add a value to the 'onclick' CLIENT-side attribute:
this.btnHome.Attributes.Add("onclick","return confirm('Are you sure to delete this Event?');");
When the user clicks the button, this CLIENT-side onclick handler executes and shows the user a CLIENT-side confirmation prompt. One of two things happens:
1. User clicks 'OK'. The confirm() method returns 'true'.
2. User clicks 'Cancel'. The confirm() method return 'false'.
This value (true/false) is being returned to the CLIENT-side event handler of the button click. Now, the onclick handler of the button on the CLIENT-side will stop if it receives 'false'. Only if it receives 'true' will it continue.
Because this button is a form submit button, the form will only submit if the handler is allowed to continue executing. By returning 'false' from the confirm() method, we are stopping execution of the handler and thus stopping the form submit.
Therefore, if the form is never submitted the page never enters a postback based on that button click. So the SERVER-side onclick handler for the button server control will not fire. Thus, you do not need any test on the SERVER-side to determine if the user pressed 'Cancel' because you stopped it at the CLIENT-side.
-
Peter