I have one problem. I validate two texboxs. If texbox are not validate I show error message with error provider.
Situation :
tbAzetId.Text="string"; tbHeslo.Text=empty;
errorprovider show error message in tbHeslo, this is ok.
Then I write some text in tbHeslo, click on button but errorprovider is still show error message in tbHeslo. Where can be problem?
Code is here:
private bool IsAzetIdValid()
{
if (tbAzetId.Text!=String.Empty && Regex.IsMatch(tbAzetId.Text, "[^a-zA-Z0-9]"))
{
return true;
}
else
{
return false;
}
}
private bool IsHesloValid()
{
if (tbHeslo.Text !=String.Empty)
{
return true;
}
else
{
return false;
}
}
private void btnPrihlasenie_Click(object sender, EventArgs e)
{
errorProvider.Clear();
if (!IsAzetIdValid())
errorProvider.SetError(tbAzetId, @"Nezadali ste Azet ID");
else if (!IsHesloValid())
errorProvider.SetError(tbHeslo, @"Nezadali ste heslo");
else
Text = "OK";
}
You'll need to clear the error provider text for that specific control when the error is cleared:
errorProvider.SetError(tbAzetId, "");
if (!IsAzetIdValid())
errorProvider.SetError(tbAzetId, @"Nezadali ste Azet ID");
errorProvider.SetError(tbHelso, "");
if (!IsHesloValid())
errorProvider.SetError(tbHeslo, @"Nezadali ste heslo");;
ErrorProvider.Clear is not enough:
To clear the error message, call the SetError method and pass in Empty for the String value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With