Why is .CavesValidation set to True by default for buttons?

When instantiating a button in a .NET WinForms application, the .CausesValidation property is set to True. Why are all buttons supposed to raise validation events? Doesn't this mean that by default all controls on a form with _Validating events will have this event when the entire button just receives focus?

Can't get focus on a button a little early to trigger validation events? Especially the default? Button click seems like a much better default time to check.

I'm asking because I want to make sure I understand the WinForms validation pattern correctly.

+2


source to share


1 answer


I think this is the safest of two evils. Often, buttons process data; this way, if you do nothing, then by default your data will be validated and it will be pretty obvious (since it won't work) if you don't really want to validate it.

Contrast with alternative - you don't do anything and your button silently works successfully performing actions on invalid data and you don't notice because it's thin.



The former is probably safer, even if it is mildly irritating.

+3


source







All Articles