Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public void NoCustomDescriptor()
        {
            PropertyDescriptor pd = BaseValidator.GetValidationProperty(new TextBox());

            Assert.AreEqual("Text", pd.Name);
        }
Exemplo n.º 4
0
 public new PropertyDescriptor GetValidationProperty(object o)
 {
     return(BaseValidator.GetValidationProperty(o));
 }