Example #1
0
        private void RegisterRestrict(MvcRestrictAttribute attribute, ControlPropertyMapping controlPropertyMapping, string property)
        {
            HtmlInputHidden hidden = new HtmlInputHidden();

            if (controlPropertyMapping != null)
            {
                WebControl targetControl = FindControl(controlPropertyMapping.ControlToValidate) as WebControl;
                hidden.Attributes.Add("ControlToValidate", (targetControl == null) ? controlPropertyMapping.ControlToValidate : targetControl.ClientID);
            }

            hidden.Attributes.Add("ValidateType", ".");
            hidden.Attributes.Add("Property", property);
            hidden.Attributes.Add("IsPreventPaste", attribute.IsPreventPaste ? "1" : "0");
            hidden.Attributes.Add("AllowExpression", attribute.AllowExpression);
            hidden.Attributes.Add("WaterMark", attribute.WaterMark);

            Controls.Add(hidden);
        }
Example #2
0
        private void RegisterClientValidationInfo(MvcValidationAttribute attribute, ControlPropertyMapping controlPropertyMapping, string property, string parent)
        {
            HtmlInputHidden hidden = new HtmlInputHidden();

            if (controlPropertyMapping != null)
            {
                WebControl targetControl = FindControl(controlPropertyMapping.ControlToValidate) as WebControl;
                hidden.Attributes.Add("ControlToValidate", (targetControl == null) ? controlPropertyMapping.ControlToValidate : targetControl.ClientID);
            }

            if (!string.IsNullOrEmpty(parent))
            {
                hidden.Attributes.Add("Parent", parent);
            }

            hidden.Attributes.Add("Property", property);
            hidden.Attributes.Add("IngoreTaret", attribute.IngoreTaret);
            hidden.Attributes.Add("IngoreValue", attribute.IngoreValue);
            hidden.Attributes.Add("ErrorMessage", attribute.ErrorMessage);
            hidden.Attributes.Add("ValidateType", attribute.ValidationType.ToString());

            switch (attribute.ValidationType)
            {
                case MvcValidationType.MvcRequired:
                    hidden.Attributes.Add("InitialValue", (attribute as MvcRequiredAttribute).InitialValue);
                    break;

                case MvcValidationType.MvcRegularExpression:
                    hidden.Attributes.Add("Pattern", (attribute as MvcRegularExpressionAttribute).Pattern);
                    break;

                case MvcValidationType.MvcDateFormat:
                    hidden.Attributes.Add("DateFormat", (attribute as MvcDateFormatAttribute).DateFormat);
                    hidden.Attributes.Add("CommonErrorMessage", (attribute as MvcDateFormatAttribute).CommonErrorMessage);
                    hidden.Attributes.Add("MessageOfInValidDate", (attribute as MvcDateFormatAttribute).MessageOfInValidDate);
                    hidden.Attributes.Add("MessageOfInValidYear", (attribute as MvcDateFormatAttribute).MessageOfInValidYear);
                    break;

                case MvcValidationType.MvcCompare:
                    hidden.Attributes.Add("CompareToValue", (attribute as MvcCompareAttribute).CompareToValue);
                    hidden.Attributes.Add("DataType", (attribute as MvcCompareAttribute).DataType.ToString().ToLower());
                    hidden.Attributes.Add("CompareOperator", (attribute as MvcCompareAttribute).CompareOperator.ToString());
                    hidden.Attributes.Add("AlwaysTrueForNullValue", (attribute as MvcCompareAttribute).AlwaysTrueForNullValue ? "1" : "0");
                    break;

                case MvcValidationType.MvcTextFilter:
                    int minLength = (attribute as MvcTextFilterAttribute).MinLenth;
                    int maxLength = (attribute as MvcTextFilterAttribute).MaxLength;

                    if (maxLength != 0 && maxLength <= minLength)
                        throw new Exception("maxLength should greater than minLength!");

                    hidden.Attributes.Add("ValidateEmptyText", (attribute as MvcTextFilterAttribute).ValidateEmptyText ? "1" : "0");
                    hidden.Attributes.Add("MaxLength", maxLength.ToString());
                    hidden.Attributes.Add("MinLenth", minLength.ToString());
                    hidden.Attributes.Add("MessageOfMaxLength", (attribute as MvcTextFilterAttribute).MessageOfMaxLength);
                    hidden.Attributes.Add("MessageOfMinLength", (attribute as MvcTextFilterAttribute).MessageOfMinLength);
                    break;

                case MvcValidationType.MvcCustomer:
                    hidden.Attributes.Add("ValidateEmptyText", (attribute as MvcCustomerAttribute).ValidateEmptyText ? "1" : "0");
                    hidden.Attributes.Add("ClientValidationFunction", (attribute as MvcCustomerAttribute).ClientValidationFunction);
                    break;
            }

            Controls.Add(hidden);
        }