Text Box Validation

D

daudi

I have a text box which i validate at LostFocus Event. My problem is
that if user click at cancel it also validates this thex box and
brings a error message. I do go about it in that when it is cancel
button click then it should not validate the text box and instead
unload the form.
Thanks
 
R

rowe_newsgroups

Check out the validation event for the textbox and the
CausesValidation property of the cancel button.

Thanks,

Seth Rowe
 
R

rowe_newsgroups

Actually, there isn't much code involved, all you need to do is move
the code you have in the LostFocus event to the validating event. That
gives you access to the the ValidatingEventArgs object which has a
cancel property. So if the text isn't valid then just type e.Cancel =
True and then the program will automagically take care of the rest
(preventing focus from changing). After that is set, all (I think)
standard controls have a CausesValidation property that is normally
set to true. When focus changes to a new control, if this property is
set to true it fires the Validating event for the control who had the
focus last. So setting this to false (for your cancel button) will
stop the validating event from firing when you click on the button.

Hope that makes sense

Thanks,

Seth Rowe
 
D

daudi

thanks alot

daudi
Actually, there isn't much code involved, all you need to do is move
the code you have in the LostFocus event to the validating event. That
gives you access to the the ValidatingEventArgs object which has a
cancel property. So if the text isn't valid then just type e.Cancel =
True and then the program will automagically take care of the rest
(preventing focus from changing). After that is set, all (I think)
standard controls have a CausesValidation property that is normally
set to true. When focus changes to a new control, if this property is
set to true it fires the Validating event for the control who had the
focus last. So setting this to false (for your cancel button) will
stop the validating event from firing when you click on the button.

Hope that makes sense

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top