[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 628
  • Last Modified:

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.

  • 2
1 Solution

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
You can even add a label in the control to automatically display your error message.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now