
How to validate text box contents in validating event as well as assignment
No, this won't work. I already have this routine & it gets fired when my form is already running & I change the value in the text
box. The problem is when I change the value in another routine, the validating does not get called. For example:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text &= "test"
End Sub
If I do something like the above, the validating event does NOT get triggered. The event TextChanged gets triggered, but if I use
that, then if the user starts typing in a new value in that field, TextChanged event triggers every time the enter a new character.
So, is there any way of telling .NET to validate the data in both of these cases?
Thank you,
Omid
Quote:
> Omid,
> This is example will not let you tab off the textbox if there is nothing
> in it.
> Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
> System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
> If TextBox1.Text = "" Then
> MessageBox.Show("Please Enter a Value")
> e.Cancel = True
> End If
> End Sub
> Ken
> --------------
> > I have a text box. In the program, I load this as follows:
> > TextBox1.text = SomeOtherVariable
> > I have a routine that handles validating event for text box, but this
> routine is not getting called when I set it as above. It only
> > gets called when I actually change the text via the interface in run time.
> > I also don't want to use event TextChanged because this event gets called
> every time a single character in the text box changes.
> > My goal is to validate this text box's text when it is loaded with data
> with an assignment statement as well as when the validating
> > event fires up. Is there any way I can accomplish this?
> > Thanks,
> > Omid