How to validate text box contents in validating event as well as assignment 
Author Message
 How to validate text box contents in validating event as well as assignment

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



Sat, 19 Nov 2005 09:25:20 GMT  
 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



Sat, 19 Nov 2005 23:10:40 GMT  
 How to validate text box contents in validating event as well as assignment
For the validating event to fire the control must have the focus:

Simple example:

TextBox1.text = SomeOtherVariable
TextBox1.Focus

'Triggers validating when focus changes

Vince


Quote:
> 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
Quote:
> 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.
Quote:

> 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
Quote:
> event fires up.  Is there any way I can accomplish this?

> Thanks,
> Omid



Mon, 21 Nov 2005 04:59:22 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Form's validate does not fire usercontrol(inside textbox) validating event

2. Validating, Validated, LostFocus Event Order

3. Validating text entered in a text box??????

4. Combo box and validate event

5. Validating resource assignment

6. Validating keystrokes into a Text Box

7. Validating/Validated questions

8. How validate the information in the text box?

9. Validate Text Box

10. validating a date in a text box

11. Validating Text Boxes in VB5

12. Validate Text Box

 

 
Powered by phpBB® Forum Software