CausesValidation Property Does Not Trigger Validate Event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have simple app with a textBox, a button and errorProvider. I have all the
controls CausesValidation set to true, and the following code:

private void textBox1_Validation(object sender, CancelEventArgs e)
{
string error = null;
if( textBox1.Text.Length == 0 )
{
error = "Please enter a name";
e.Cancel = true;
}
errorProvider1.SetError((Control)sender, error);
}

This event fails to fire even though I tab over to another control without
putting anything in the textbox. I've researched the internet and have come
up empty. Does anyone know whether there is something that I am failing to
do. Thanks
 
I have simple app with a textBox, a button and errorProvider. I have all the
controls CausesValidation set to true, and the following code:

private void textBox1_Validation(object sender, CancelEventArgs e)
{
string error = null;
if( textBox1.Text.Length == 0 )
{
error = "Please enter a name";
e.Cancel = true;
}
errorProvider1.SetError((Control)sender, error);
}

This event fails to fire even though I tab over to another control without
putting anything in the textbox. I've researched the internet and have come
up empty. Does anyone know whether there is something that I am failing to
do. Thanks

Have you verified that there is no space character in the TextBoc control? Do
you have the form's AutoValidate property set properly?

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 

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

Back
Top