tags:

views:

24

answers:

2

Hi, 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";
    }
+3  A: 

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.

Michael Petrotta
sory, it doesnt work :(
John
@John: It does work. If you're having problems with it, you'll need to be more specific. You may want to try just the error clearing and setting in a separate test function or app, to try to isolate the problem.
Michael Petrotta
+2  A: 

Use errorProvider.SetError(ctlName, "") to clear the error message from a control.

Richard Hein