Log in | Jump |

jhollingworth

a blog about my life (twitter.com/jhollingworth)
This thing was constructed on December 5, 2008, and it was categorized as ASP.NET, C#.
You can follow comments through the RSS 2.0 feed. You can leave a comment, or trackback.

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;
	}
}
This thing was constructed by .


You can follow comments through the RSS 2.0 feed. You can leave a comment, or trackback.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*