I want to cancel an event from within that function scope.
Eg. I pressed button click event and on false validation, I want to cancel this event. Likewise i want to cancel other events also.
How can i do this in C#
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends on the scenario; in most cases: rather than cancel the event, just do nothing, for example:
or:
There are some events that expose a
CancelEventArgs(or similar), allowing to to cancel some external behaviour via theargs– form-closing being the most obvious example (sete.Cancel = true;).Note that in this scenario I would not have an automatic dialog-result on the button; apply that manually when (if) the handler completes successfully.