Validating multiple textboxes using errorprovider

后端 未结 3 1201
慢半拍i
慢半拍i 2021-02-03 15:06

I have 10 textboxes, now i want to check that none of them are empty when a button is clicked. My code is :

 if (TextBox1.Text == \"\")
 {
    errorProvider1.Se         


        
3条回答
  •  你的背包
    2021-02-03 15:36

    Edit:

    var controls = new [] { tx1, tx2. ...., txt10 };
    foreach(var control in controls.Where(e => String.IsNullOrEmpty(e.Text))
    {
        errorProvider1.SetError(control, "Please fill the required field");
    }
    

提交回复
热议问题