VB.Net Form Level Validation


I want to validate all the controls (validating event of the controls) in a button click. Like as we have in ASP.NET (Validation Summary).

For Example, in an Employee Master, EmpID, EmpName, Designation, DateofJoin must not be empty. This can be done using Validating Event for the individual controls. But the User may fill only EmpName and Click the SAVE button. At this stage, all the controls have to validated by manual coding like EmpName<>"", Designation<>"".

Instead of this manual coding, I want to have an existing method or a generalized function to run the Validating Event of the controls in a form.

This facility is available in ASP.Net by using Validation Summary Control. How can be the same obtained in VB.Net?

Hope all of you understand my requirement.

Thanks in advance.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


I suggest that you write a custom control that inherits from textbox (call it ValidatingTextBox). In this control you add the Validate() method (it could return a boolean or whatever). Inside this function, you make the validating tests.

Then in your form that contains the ValidatingTextBox controls, call it for each of these :

(something like this :)
for each ctrl as Control in Me.Controls
    If typeof ctrl is ValidatingTextBox then
        Ctype(ctrl, ValidatingTextBox).Validate()
    End If

Hope it helps

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You can even add a label in the control to automatically display your error message.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.