1

I want to check for empty textboxes with tag using this code:

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;
                   }
               }
           }
        }

But it gives an error :

System.NullReferenceException: 'Object reference not set to an instance of an object.'

How do I resolve this exception?

rjdkolb
  • 8,217
  • 8
  • 57
  • 77
a_fathy
  • 525
  • 1
  • 7
  • 18

0 Answers0