M
Marina
Imagine a form with some fields and an OK buttons that saves the
information. Each field has validation logic in the Validating event. If
the input is not valid, the control's value is replaced with the last value
it had before the user changed it. Pretty typical
Now, the user types some invalid value and clicks OK. The user gets a
message saying the value is not valid, and the bad value is replaced with
the last good one. So far, so good.
But, now the button's Click event fires, and the form is saved and closed.
Now, the user, would not have wanted to save the form with the old value,
since clearly they were trying to update a field in the form.
So, if the validation was not valid, we essentially want to cancel the Click
event of the button.
Now, as forms and scenarios get more complex, it becomes necessary to deal
with this issue in a more generic manner. However, it seems that doing
something like is far from easy. It can probably be done by mucking around
with timers and boolean values, but surely there must be some other built in
way to deal with this problem in windows forms?
It seems like a pretty common scenario? How do people deal with this?
information. Each field has validation logic in the Validating event. If
the input is not valid, the control's value is replaced with the last value
it had before the user changed it. Pretty typical
Now, the user types some invalid value and clicks OK. The user gets a
message saying the value is not valid, and the bad value is replaced with
the last good one. So far, so good.
But, now the button's Click event fires, and the form is saved and closed.
Now, the user, would not have wanted to save the form with the old value,
since clearly they were trying to update a field in the form.
So, if the validation was not valid, we essentially want to cancel the Click
event of the button.
Now, as forms and scenarios get more complex, it becomes necessary to deal
with this issue in a more generic manner. However, it seems that doing
something like is far from easy. It can probably be done by mucking around
with timers and boolean values, but surely there must be some other built in
way to deal with this problem in windows forms?
It seems like a pretty common scenario? How do people deal with this?