views:

292

answers:

1

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);
}
}
A: 

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.

Drithyin
No clientside info to speak of; I'm only interested in serverside validation. ShowSummary is set correctly...the ValidatorSummary will pick up other Validators on the page (if I place them there for testing purposes). No UpdatePanels, but the control is in the content tag of a "slave" to a Master page.
FloatingPoint
Ah, according to Peter Blum, it doesn't matter what your server-side validation does, if you don't have client-side validation the message won't appear. Is it just me, or are .NET validators really still rather disappointing?
FloatingPoint
I very very rarely use the built-in .NET validators because they are so shoddy. And yes, you probably need some client-side validation. It probably counts if you do an AJAX call from your page to call some validtation method in your codebehind if you want to avoid the javascript route.
Drithyin