C# validating multiple textboxes?

↘锁芯ラ 提交于 2019-12-03 20:38:09
Umar Iqbal
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.
}

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.

http://msdn.microsoft.com/en-us/library/ms227424.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!