Пример #1
0
        /// <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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        public void NoCustomDescriptor()
        {
            PropertyDescriptor pd = BaseValidator.GetValidationProperty(new TextBox());

            Assert.AreEqual("Text", pd.Name);
        }
Пример #4
0
 public new PropertyDescriptor GetValidationProperty(object o)
 {
     return(BaseValidator.GetValidationProperty(o));
 }