I have almost 20 textboxes and to check all i have to call validate event 20 times each using errorprovider. Is there any efficient way other than that.
-
I think you can get an answer to your question here: stackoverflow.com/questions/1959018/…Sven Grosen– Sven Grosen2012-06-19 20:56:57 +00:00Commented Jun 19, 2012 at 20:56
-
Thanks but i want to check validation on runtime, the link provides information about validation at the time of submission.Umar Iqbal– Umar Iqbal2012-06-19 21:02:45 +00:00Commented Jun 19, 2012 at 21:02
Add a comment
|
2 Answers
this.textBox1.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating);
this.textBox2.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating);
this.textBox3.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating);
// And so on for the 20 boxes.
private void textBox_Validating(object sender, CancelEventArgs e)
{
TextBox textbox = (TextBox)sender;
// Do whatever yo need to do with textbox here.
}
Comments
Create validators (RequiredFieldValidator or whatnot) for each of them, then assign them all to the same ValidationGroup. You can enforce validation of all the controls in that group at once.
2 Comments
Umar Iqbal
Could you be little more specific because the link redirects to asp.net and i'm working on a desktop application.
LesterDove
Sorry about that, I assumed web!