/// <summary> /// Check if the ControlToValidate is valid /// </summary> /// <returns>True if control properties is valid</returns> protected override bool EvaluateIsValid() { string value = this.GetControlValidationValue(this.ControlToValidate); DateInputBox control = this.NamingContainer.FindControl(this.ControlToValidate) as DateInputBox; if (value.Length == 0) { return(true); } if (value == this.WatermarkText) { // Essentially box is empty so return valid return(true); } // Don't raise an error for Today, Tomorrow if value is also the same. if (value == control.Value.ToString(control.DisplayDayOfWeek, false, control.DisplayDateAsText, CultureInfo.CurrentCulture)) { return(true); } NhsDate tryParseResult; if (!NhsDate.TryParseExact(value, out tryParseResult, System.Threading.Thread.CurrentThread.CurrentCulture)) { control.Value.DateType = DateType.Null; return(false); } return(true); }
/// <summary> /// Called when the associated control changes. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="ce">A ComponentChangedEventArgs that contains the event data. </param> public override void OnComponentChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs ce) { if (ce == null) { throw new ArgumentNullException("ce"); } base.OnComponentChanged(sender, ce); if (ce.Member.Name == "Value") { // user has edited Value property make sure the designer knows that // this means other properties need serializing DateInputBox control = (DateInputBox)this.Component; this.RaiseComponentChanged("DateType", control.DateType); switch (control.Value.DateType) { case DateType.Exact: case DateType.Approximate: this.RaiseComponentChanged("DateValue", control.DateValue); break; case DateType.YearMonth: this.RaiseComponentChanged("Year", control.Year); this.RaiseComponentChanged("Month", control.Month); break; case DateType.Year: this.RaiseComponentChanged("Year", control.Year); break; case DateType.NullIndex: this.RaiseComponentChanged("NullIndex", control.NullIndex); break; case DateType.Null: break; } } }
/// <summary> /// Determines whether the control specified by the ControlToValidate property is a valid control. /// </summary> /// <returns>True if control properties is valid</returns> protected override bool ControlPropertiesValid() { // Call the base implementation of ControlPropertiesValid first. // If that passes run the extra checks if (base.ControlPropertiesValid() == true) { DateInputBox control = this.NamingContainer.FindControl(this.ControlToValidate) as DateInputBox; if (control == null) { throw new HttpException(DateInputBoxControl.DateInputBoxValidatorResources.ControlToValidateInvalid); } else { return(true); } } else { return(false); } }