views:

155

answers:

1

I'm wondering how people handle a situation like this, when you have a validation event, and you need to show the user a dialog box asking him whether to continue or cancel.

The problem is that when showing that dialog box, it causes another validation event because it's considered losing focus on the control again, and you end up with an infinite loop of dialog popups.

I can't show the message box before or after the validation event either, because either the user hasn't finished editing the control, or the value has been already committed and rolling back would cause problems of its own.

What I'm doing right now is setting a flag before showing the dialog and clearing it afterward, and then in the validation event function, check if the flag is set and if it is, skip the function. It works but is cumbersome and prone to programmer errors.

Is there some easier way to handle something like that ?

+1  A: 

Take a look at the CausesValidation property on your controls. You can set whether or not a button you press causes your validation events to fire. You can also programatically set this to keep your validation logic from firing at inopportune times.

Dave Markle