简体   繁体   中英

Validator not passing ErrorMessage to ValidationSummary

I have written my own Validator and although the validator appears to be working (as it does display the Text property when invalid) the ValidationSummary does not display the ErrorMessage property, or anything, when validation fails. Interestingly, it appears that it fails to even display the Text property when I add another control with a validator to the page. What am I doing wrong?

public class RequiredCheckBoxListValidator : BaseValidator
{
private CheckBoxList _list;
private int _requiredCount = 1;

public int RequiredCount
{
  get { return _requiredCount; }
  set { _requiredCount = value; }
}

public RequiredCheckBoxListValidator() 
{
  EnableClientScript = false;
}

protected override bool ControlPropertiesValid()
{
  Control control = FindControl(ControlToValidate);

  if (control != null)
  {
    _list = (CheckBoxList)control;
    return (_list != null);
  }
  else
  {
    return false;
  }
}

protected override bool EvaluateIsValid()
{
  return (_list.Items.Cast<ListItem>().Where(li => li.Selected).Count() == _requiredCount);
}
}

It would help to see your clientside info.

Without that, my guesses are to check ShowSummary on the validtorsummary to make sure it is not hiding the summary, and to see if the validators and summary are in separate UpdatePanels.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM