检查带有标记的空文本框

时间:2017-09-15 12:09:15

标签: c# textbox tags

我想使用以下代码检查带有标记的空文本框:

private void btnSave_Click(object sender, EventArgs e)
        {
            foreach (Control ctl in groupBox1.Controls)
            {
                if (ctl is TextBox)
                {
                if (ctl.Tag.Equals("*") && string.IsNullOrEmpty(ctl.Text))
                   {
                    ctl.BackColor = Color.Red;
                   }
                else
                   {
                    ctl.BackColor = Color.White;
                   }
               }
           }
        }

但是它给出了一个错误:

  

System.NullReferenceException:'对象引用未设置为   对象的实例。'

如何解决此异常?

0 个答案:

没有答案
相关问题