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?