Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set errormessage for customvalidator?

I would like to use a customvalidator control to handle all my validation, but I can't figure out how to set the error message in the code-behind for different checks. Is this possible?

like image 841
chobo Avatar asked Sep 21 '11 18:09

chobo


1 Answers

You can set the error message in the OnServerValidate method as you wish based on your validation logic:

protected void customValidator1_Validate(object sender, ServerValidateEventArgs e)
{
    if (e.Value.Length < 5)
    {
        e.IsValid = true;
    }
    else
    {
        customValidator1.ErrorMessage = "Length must be less than 5.";
        e.IsValid = false;
    }
}
like image 153
jdavies Avatar answered Oct 27 '22 06:10

jdavies