About jhollingworth
a blog about my life (twitter.com/jhollingworth)
Feed Subscriptions
Today I need to validate that a user had entered a date in an asp.net calender only to find that there were no solutions for it so for future reference, if you want a calendar validator use the following:
public class CalendarValidator : BaseValidator
{
protected override bool ControlPropertiesValid()
{
return true;
}
protected override bool EvaluateIsValid()
{
var control = Parent.FindControl(ControlToValidate) as Calendar;
if(null == control)
{
throw new NullReferenceException(
string.Format(”Could not find the control with id {0} on the page”, ControlToValidate)
);
}
if(DateTime.MinValue == control.SelectedDate)
{
return false;
}
return true;
}
}
