mikewhorley
New member
- Joined
- May 29, 2011
- Messages
- 3
- Programming Experience
- Beginner
I have a form with 20 textboxes that I would like to perform validation on. The validation rules of the textboxes are the same.
An example with 2 textboxes
This works but it means I have to list 20 textboxes in the handles part. Is there a better approach?
An example with 2 textboxes
VB.NET:
Private Sub txtName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles[B]TextBox1.Validating,TextBox2.Validating[/B]
If CType(sender, TextBox).Text = "" Then
ErrProvider.SetError(sender, "Must Be filled")
Else
ErrProvider.SetError(sender, "")
End If
This works but it means I have to list 20 textboxes in the handles part. Is there a better approach?