/// <summary> /// Gets the control validation value. /// </summary> /// <remarks> /// Based on the reflected source of <see cref="BaseValidator.GetControlValidationValue"/>. /// </remarks> /// <param name="name">The name.</param> /// <returns></returns> private string GetControlValidationValue(string name) { Control valueControl = NamingContainer.FindControl(name); if (valueControl == null) { return(null); } PropertyDescriptor validationProperty = BaseValidator.GetValidationProperty(valueControl); if (validationProperty == null) { return(null); } object value = validationProperty.GetValue(valueControl); if (value is ListItem) { return(((ListItem)value).Value); } if (value != null) { return(value.ToString()); } return(String.Empty); }
private static void SetControlValidationValue(Control validator, string controlName, string value) { Guard.ArgumentNotNull(validator, "validator"); Control component = validator.NamingContainer.FindControl(controlName); if (component == null) { string message = string.Format(CultureInfo.CurrentCulture, Resources.CannotFindControlToValidate, controlName); throw new InvalidOperationException(message); } PropertyDescriptor validationProperty = BaseValidator.GetValidationProperty(component); if (validationProperty == null) { string message = string.Format(CultureInfo.CurrentCulture, Resources.NoValidationProperty, controlName); throw new InvalidOperationException(message); } validationProperty.SetValue(component, value); }
public void NoCustomDescriptor() { PropertyDescriptor pd = BaseValidator.GetValidationProperty(new TextBox()); Assert.AreEqual("Text", pd.Name); }
public new PropertyDescriptor GetValidationProperty(object o) { return(BaseValidator.GetValidationProperty(o)); }