How to fire validated event on text box?

  • Thread starter Thread starter Claire Reed
  • Start date Start date
C

Claire Reed

I have one textbox on a form, I want the validated event for that
textbox to fire when the user clicks away from that form (I have many
forms open at a time). Currently the validated event is not fired and
I think this happens because it is suppressed when a form is left. Is
that true? What is the best way to get the validated event for a
textbox to fire when a form is left in C#?

thanks for any help

Claire
 
In the Form Deactivate event, you can fire the validating event of the
textbox.

Two ways:
1. The quick hack way is to use reflection to call the protected
OnValidating() method of the textbox.

2. The correct way is to derive a class from textbox that provides a
public method that called the protected OnValidating() method

3. Another quick hack way is to make the focus move away from the
textbox and then set it back.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
Another way to fire the validating event is to call
ContainerControl.Validate on the container that
the TextBox resides on

/claes
 
Thank you both for your suggestions.

Claire

Claes Bergefall said:
Another way to fire the validating event is to call
ContainerControl.Validate on the container that
the TextBox resides on

/claes
 
Back
Top