Hi Friend ! Just try this code !!! This will sure solve your problem.
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
errorProvider1.SetError(textBox1, "Please Enter the value in First Box.");
MessageBox.Show("Data not Submitted", "Form", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox1.Focus();
}
else if (textBox2.Text == "")
{
errorProvider1.SetError(textBox2, "Please Enter the value in Second Box.");
MessageBox.Show("Data not Submitted", "Form", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox2.Focus();
}
else
{
MessageBox.Show("Data Submitted", "Form", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
errorProvider1.SetError(textBox1, "");
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text != "")
{
errorProvider1.SetError(textBox2, "");
}
}
If any problem, then plz reply or comment.