Change textbox color if textbox is empty in asp.net using c#
private void button1_Click(object sender, EventArgs e)
{
textBox1.BackColor = Color.White;
textBox2.BackColor = Color.White;
textBox3.BackColor = Color.White;
textBox4.BackColor = Color.White;
string[] text = new string[4];
text[0] = System.Convert.ToString(textBox1.Text);
text[1] = System.Convert.ToString(textBox2.Text);
text[2] = System.Convert.ToString(textBox3.Text);
text[3] = System.Convert.ToString(textBox4.Text);
for (int i = 0; i <= 3; i++)
{
if (text == "")
{
errorshow(i);
}
}
}
private void errorshow(int k)
{
switch (k)
{
case 0:
textBox1.BackColor = Color.Red;
break;
case 1:
textBox2.BackColor = Color.Red;
break;
case 2:
textBox3.BackColor = Color.Red;
break;
case 3:
textBox4.BackColor = Color.Red;
break;
}
}