Force the validation of a TextBox
Posted on 2004-04-16
I have a form with several custom textboxes. For each textbox, I have overriden the OnValidating method (or handling the Validating event) to validate the input and display an error using an errorProvider.
So the validation is done when the user is filling the form.
But when I want to save the form, I want to revalidate everything (to get some Ids from database, ...). To do that I want to force the validation of each control and I was looping on all controls and calling the Focus method.
This is quite dirty I think and visually, the effect is not really nice.
So I was thinking about implementing a Validate public method on my Textbox. This method will call internally the protected OnValidating method. The result will be the same but without any ugly visual effect.
What is your opinion about that solution ? Don't you think that using a public method to call a protected method is breaking the encapsulation of the Textbox ?
Do you have any other / better solution ?