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
  • 10,377
  • 11
  • 69
  • 89
John Deck
  • 787
  • 1
  • 12
  • 27

0 Answers0