ErrorProvider

Aje68

New member
Joined
Jan 18, 2010
Messages
2
Programming Experience
5-10
Hi,

I have a form with about 40 textboxes, but only 7 of them need to have a value in order to save. My question is; is it totally wrong to validate these 7 fields on the form rather then in the relevant business object? The reason I'm asking is that although I'm happy to do the validation in the business object, I'm struggling to find a way to use the ErrorProvider that's on the form.

Any thoughts?
 
What is your struggle with ErrorProvider? One typically use the Validating event for the controls to set/clear ErrorProvider error and set the validation result, with the forms ValidateChildren function you can force validation for all validating controls and see if they passes before submitting the data, this will then also show the error icon for each control that does not validate.
 
If you're looking to separate the logic in your app then you should have a service layer that handles validation. The presentation layer will pass the data to the service layer and the service layer will perform the validation. That might involve logic internal or external to the business objects themselves, but the presentation layer will be unaware either way. It's the service layer that takes care of that. The service layer will then pass back a Boolean value to the presentation layer to indicate whether validation was successful and, if it wasn't, a list of errors. What form that list takes is up to you but a Dictionary of some sort would be a good place to start.
 
If you're looking to separate the logic in your app then you should have a service layer that handles validation. The presentation layer will pass the data to the service layer and the service layer will perform the validation. That might involve logic internal or external to the business objects themselves, but the presentation layer will be unaware either way. It's the service layer that takes care of that. The service layer will then pass back a Boolean value to the presentation layer to indicate whether validation was successful and, if it wasn't, a list of errors. What form that list takes is up to you but a Dictionary of some sort would be a good place to start.

Thanks, I'll look into that option.
 
Back
Top