Esempio n. 1
0
        /// <include file='doc\ValidationSummary.uex' path='docs/doc[@for="ValidationSummary.AddAttributesToRender"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    AddAttributesToRender method.
        /// </devdoc>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);

            if (renderUplevel)
            {
                // We always want validation cotnrols to have an id on the client, so if it's null, write it here.
                // Otherwise, base.RenderAttributes takes care of it.
                // REVIEW: this is a bit hacky.
                if (ID == null)
                {
                    writer.AddAttribute("id", ClientID);
                }

                if (HeaderText.Length > 0)
                {
                    writer.AddAttribute("headertext", HeaderText, true);
                }
                if (ShowMessageBox)
                {
                    writer.AddAttribute("showmessagebox", "True");
                }
                if (!ShowSummary)
                {
                    writer.AddAttribute("showsummary", "False");
                }
                if (DisplayMode != ValidationSummaryDisplayMode.BulletList)
                {
                    writer.AddAttribute("displaymode", PropertyConverter.EnumToString(typeof(ValidationSummaryDisplayMode), DisplayMode));
                }
            }
        }
Esempio n. 2
0
        /// <internalonly/>
        /// <devdoc>
        ///    <para> Checks the properties of a the control for valid values.</para>
        /// </devdoc>
        protected override bool ControlPropertiesValid()
        {
            // Check the control id references
            if (ControlToCompare.Length > 0)
            {
                CheckControlValidationProperty(ControlToCompare, "ControlToCompare");

                if (StringUtil.EqualsIgnoreCase(ControlToValidate, ControlToCompare))
                {
                    throw new HttpException(SR.GetString(SR.Validator_bad_compare_control,
                                                         ID,
                                                         ControlToCompare));
                }
            }
            else
            {
                // Check Values
                if (Operator != ValidationCompareOperator.DataTypeCheck &&
                    !CanConvert(ValueToCompare, Type, CultureInvariantValues))
                {
                    throw new HttpException(
                              SR.GetString(SR.Validator_value_bad_type,
                                           new string [] {
                        ValueToCompare,
                        "ValueToCompare",
                        ID,
                        PropertyConverter.EnumToString(typeof(ValidationDataType), Type),
                    }));
                }
            }
            return(base.ControlPropertiesValid());
        }
        public string ToString(IFormatProvider formatProvider)
        {
            string str = string.Empty;

            if (this.IsEmpty)
            {
                return(str);
            }
            switch (this.type)
            {
            case FontSize.AsUnit:
                return(this.value.ToString(formatProvider));

            case FontSize.XXSmall:
                return("XX-Small");

            case FontSize.XSmall:
                return("X-Small");

            case FontSize.XLarge:
                return("X-Large");

            case FontSize.XXLarge:
                return("XX-Large");
            }
            return(PropertyConverter.EnumToString(typeof(FontSize), this.type));
        }
Esempio n. 4
0
 public void EnumToString()
 {
     Assert.AreEqual(PropertyConverter.EnumToString(typeof(TestEnum), 1),
                     "Normal", "Normal");
     Assert.AreEqual(PropertyConverter.EnumToString(typeof(TestEnum), 25),
                     "25", "Decimal");
 }
Esempio n. 5
0
        // <summary>
        //  AddAttributesToRender method
        // </summary>

        /// <internalonly/>
        /// <devdoc>
        ///    <para>Adds the attributes of this control to the output stream for rendering on the
        ///       client.</para>
        /// </devdoc>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            if (RenderUplevel)
            {
                string         id = ClientID;
                HtmlTextWriter expandoAttributeWriter = (EnableLegacyRendering || IsUnobtrusive) ? writer : null;
                AddExpandoAttribute(expandoAttributeWriter, id, "evaluationfunction", "CompareValidatorEvaluateIsValid", false);
                if (ControlToCompare.Length > 0)
                {
                    string controlToCompareID = GetControlRenderID(ControlToCompare);
                    AddExpandoAttribute(expandoAttributeWriter, id, "controltocompare", controlToCompareID);
                    AddExpandoAttribute(expandoAttributeWriter, id, "controlhookup", controlToCompareID);
                }
                if (ValueToCompare.Length > 0)
                {
                    string valueToCompareString = ValueToCompare;
                    if (CultureInvariantValues)
                    {
                        valueToCompareString = ConvertCultureInvariantToCurrentCultureFormat(valueToCompareString, Type);
                    }
                    AddExpandoAttribute(expandoAttributeWriter, id, "valuetocompare", valueToCompareString);
                }
                if (Operator != ValidationCompareOperator.Equal)
                {
                    AddExpandoAttribute(expandoAttributeWriter, id, "operator", PropertyConverter.EnumToString(typeof(ValidationCompareOperator), Operator), false);
                }
            }
        }
Esempio n. 6
0
 public void EnumToStringFlags()
 {
     Assert.AreEqual(PropertyConverter.EnumToString(typeof(TestFlags), 0),
                     "A", "A");
     Assert.AreEqual(PropertyConverter.EnumToString(typeof(TestFlags), 3),
                     "B, C", "Multiple");
 }
 protected override void AddAttributesToRender(HtmlTextWriter writer)
 {
     base.AddAttributesToRender(writer);
     if (base.RenderUplevel)
     {
         string         clientID = this.ClientID;
         HtmlTextWriter writer2  = base.EnableLegacyRendering ? writer : null;
         base.AddExpandoAttribute(writer2, clientID, "evaluationfunction", "CompareValidatorEvaluateIsValid", false);
         if (this.ControlToCompare.Length > 0)
         {
             string controlRenderID = base.GetControlRenderID(this.ControlToCompare);
             base.AddExpandoAttribute(writer2, clientID, "controltocompare", controlRenderID);
             base.AddExpandoAttribute(writer2, clientID, "controlhookup", controlRenderID);
         }
         if (this.ValueToCompare.Length > 0)
         {
             string valueToCompare = this.ValueToCompare;
             if (base.CultureInvariantValues)
             {
                 valueToCompare = base.ConvertCultureInvariantToCurrentCultureFormat(valueToCompare, base.Type);
             }
             base.AddExpandoAttribute(writer2, clientID, "valuetocompare", valueToCompare);
         }
         if (this.Operator != ValidationCompareOperator.Equal)
         {
             base.AddExpandoAttribute(writer2, clientID, "operator", PropertyConverter.EnumToString(typeof(ValidationCompareOperator), this.Operator), false);
         }
     }
 }
Esempio n. 8
0
        /////////////////////////////////////////////////////////////////////
        // Helper function adopted from WebForms CompareValidator
        /////////////////////////////////////////////////////////////////////

        /// <include file='doc\CompareValidator.uex' path='docs/doc[@for="CompareValidator.ControlPropertiesValid"]/*' />
        protected override bool ControlPropertiesValid()
        {
            // Check the control id references
            if (ControlToCompare.Length > 0)
            {
                CheckControlValidationProperty(ControlToCompare, "ControlToCompare");
                if (String.Compare(ControlToValidate, ControlToCompare, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    throw new ArgumentException(SR.GetString(
                                                    SR.CompareValidator_BadCompareControl, ID, ControlToCompare));
                }
            }
            else
            {
                // Check Values
                if (Operator != ValidationCompareOperator.DataTypeCheck &&
                    !WebCntrls.BaseCompareValidator.CanConvert(ValueToCompare, Type))
                {
                    throw new ArgumentException(SR.GetString(
                                                    SR.Validator_ValueBadType,
                                                    ValueToCompare,
                                                    "ValueToCompare",
                                                    ID,
                                                    PropertyConverter.EnumToString(
                                                        typeof(ValidationDataType), Type)
                                                    ));
                }
            }
            return(base.ControlPropertiesValid());
        }
Esempio n. 9
0
        /// <include file='doc\CompareValidator.uex' path='docs/doc[@for="CompareValidator.ControlPropertiesValid"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    <para> Checks the properties of a the control for valid values.</para>
        /// </devdoc>
        protected override bool ControlPropertiesValid()
        {
            // Check the control id references
            if (ControlToCompare.Length > 0)
            {
                CheckControlValidationProperty(ControlToCompare, "ControlToCompare");

                if (string.Compare(ControlToValidate, ControlToCompare, true, CultureInfo.InvariantCulture) == 0)
                {
                    throw new HttpException(HttpRuntime.FormatResourceString(SR.Validator_bad_compare_control,
                                                                             ID,
                                                                             ControlToCompare));
                }
            }
            else
            {
                // Check Values
                if (Operator != ValidationCompareOperator.DataTypeCheck &&
                    !CanConvert(ValueToCompare, Type))
                {
                    throw new HttpException(
                              HttpRuntime.FormatResourceString(
                                  SR.Validator_value_bad_type,
                                  new string [] {
                        ValueToCompare,
                        "ValueToCompare",
                        ID,
                        PropertyConverter.EnumToString(typeof(ValidationDataType), Type),
                    }));
                }
            }
            return(base.ControlPropertiesValid());
        }
Esempio n. 10
0
        /// <summary>
        /// Adds the HTML attributes and styles of a <see cref="T:System.Web.UI.WebControls.Label"/> control to render to the specified output stream.
        /// </summary>
        /// <param name="writer">An <see cref="T:System.Web.UI.HtmlTextWriter"/> that represents the output stream to render HTML content on the client.</param>
        /// <exception cref="T:System.Web.HttpException">The control specified in the <see cref="P:System.Web.UI.WebControls.Label.AssociatedControlID"/> property cannot be found.</exception>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            bool flag = !Enabled;

            if (flag)
            {
                Enabled = true;
            }
            try
            {
                if (RenderUplevel)
                {
                    base.EnsureID();
                    string clientID = ClientID;
                    //HtmlTextWriter writer2 = base.EnableLegacyRendering ? writer : null;
                    HtmlTextWriter writer2 = writer;
                    if (ControlToValidate.Length > 0)
                    {
                        AddExpandoAttribute(writer2, clientID, "controltovalidate",
                                            GetControlRenderID(ControlToValidate));
                    }
                    if (SetFocusOnError)
                    {
                        AddExpandoAttribute(writer2, clientID, "focusOnError", "t", false);
                    }
                    if (ErrorMessage.Length > 0)
                    {
                        AddExpandoAttribute(writer2, clientID, "errormessage", ErrorMessage);
                    }
                    ValidatorDisplay enumValue = Display;
                    if (enumValue != ValidatorDisplay.Static)
                    {
                        AddExpandoAttribute(writer2, clientID, "display",
                                            PropertyConverter.EnumToString(typeof(ValidatorDisplay), enumValue), false);
                    }
                    if (!IsValid)
                    {
                        AddExpandoAttribute(writer2, clientID, "isvalid", "False", false);
                    }
                    if (flag)
                    {
                        AddExpandoAttribute(writer2, clientID, "enabled", "False", false);
                    }
                    if (ValidationGroup.Length > 0)
                    {
                        AddExpandoAttribute(writer2, clientID, "validationGroup", ValidationGroup);
                    }
                }
                base.AddAttributesToRender(writer);
            }
            finally
            {
                if (flag)
                {
                    Enabled = false;
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        ///		Adds the HTML attributes and styles that need to be rendered for the control to the specified <see cref='System.Web.UI.HtmlTextWriter'/> object.
        /// </summary>
        /// <param name="writer">A <see cref='System.Web.UI.HtmlTextWriter'/> that contains the output stream for rendering on the client.</param>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            if (RenderUplevel)
            {
                WebControls.ValidationDataType type = Type;
                if (type != WebControls.ValidationDataType.String)
                {
                    string         id = ClientID;
                    HtmlTextWriter expandoAttributeWriter = (EnableLegacyRendering) ? writer : null;

                    AddExpandoAttribute(expandoAttributeWriter, id, "type", PropertyConverter.EnumToString(typeof(WebControls.ValidationDataType), type), false);

                    NumberFormatInfo info = NumberFormatInfo.CurrentInfo;
                    if (type == WebControls.ValidationDataType.Double)
                    {
                        string decimalChar = info.NumberDecimalSeparator;
                        AddExpandoAttribute(expandoAttributeWriter, id, "decimalchar", decimalChar);
                    }
                    else if (type == WebControls.ValidationDataType.Currency)
                    {
                        string decimalChar = info.CurrencyDecimalSeparator;
                        AddExpandoAttribute(expandoAttributeWriter, id, "decimalchar", decimalChar);

                        string groupChar = info.CurrencyGroupSeparator;
                        // Map non-break space onto regular space for parsing
                        if (groupChar[0] == 160)
                        {
                            groupChar = " ";
                        }
                        AddExpandoAttribute(expandoAttributeWriter, id, "groupchar", groupChar);

                        int digits = info.CurrencyDecimalDigits;
                        AddExpandoAttribute(expandoAttributeWriter, id, "digits", digits.ToString(NumberFormatInfo.InvariantInfo), false);

                        // VSWhidbey 83165
                        int groupSize = GetCurrencyGroupSize(info);
                        if (groupSize > 0)
                        {
                            AddExpandoAttribute(expandoAttributeWriter, id, "groupsize", groupSize.ToString(NumberFormatInfo.InvariantInfo), false);
                        }
                    }
                    else if (type == WebControls.ValidationDataType.Date)
                    {
                        AddExpandoAttribute(expandoAttributeWriter, id, "dateorder", GetDateElementOrder(), false);
                        AddExpandoAttribute(expandoAttributeWriter, id, "cutoffyear", CutoffYear.ToString(NumberFormatInfo.InvariantInfo), false);

                        // VSWhidbey 504553: The changes of this bug make client-side script not
                        // using the century attribute anymore, but still generating it for
                        // backward compatibility with Everett pages.
                        int currentYear = DateTime.Today.Year;
                        int century     = currentYear - (currentYear % 100);
                        AddExpandoAttribute(expandoAttributeWriter, id, "century", century.ToString(NumberFormatInfo.InvariantInfo), false);
                    }
                }
            }
        }
Esempio n. 12
0
        //public static void DoBaseCompareValidatorAddAttributes(WhidbeyBaseCompareValidator validator, IBaseCompareValidatorAccessor validatorAccessor) {
        //    if (validatorAccessor.RenderUpLevel) {
        //        ValidationDataType type = validator.Type;
        //        if (type != ValidationDataType.String) {
        //            string id = validator.ClientID;

        //            ValidatorHelper.AddExpandoAttribute(validator, id, "type", PropertyConverter.EnumToString(typeof(ValidationDataType), type), false);

        //            NumberFormatInfo info = NumberFormatInfo.CurrentInfo;
        //            if (type == ValidationDataType.Double) {
        //                string decimalChar = info.NumberDecimalSeparator;
        //                ValidatorHelper.AddExpandoAttribute(validator, id, "decimalchar", decimalChar);
        //            }
        //            else if (type == ValidationDataType.Currency) {
        //                string decimalChar = info.CurrencyDecimalSeparator;
        //                ValidatorHelper.AddExpandoAttribute(validator, id, "decimalchar", decimalChar);

        //                string groupChar = info.CurrencyGroupSeparator;
        //                if (groupChar[0] == 160)
        //                    groupChar = " ";
        //                ValidatorHelper.AddExpandoAttribute(validator, id, "groupchar", groupChar);

        //                int digits = info.CurrencyDecimalDigits;
        //                ValidatorHelper.AddExpandoAttribute(validator, id, "digits", digits.ToString(NumberFormatInfo.InvariantInfo), false);

        //                int groupSize = GetCurrencyGroupSize(info);
        //                if (groupSize > 0) {
        //                    ValidatorHelper.AddExpandoAttribute(validator, id, "groupsize", groupSize.ToString(NumberFormatInfo.InvariantInfo), false);
        //                }
        //            }
        //            else if (type == ValidationDataType.Date) {
        //                ValidatorHelper.AddExpandoAttribute(validator, id, "dateorder", validatorAccessor.GetDateElementOrder(), false);
        //                ValidatorHelper.AddExpandoAttribute(validator, id, "cutoffyear", validatorAccessor.CutoffYear.ToString(NumberFormatInfo.InvariantInfo), false);

        //                int currentYear = DateTime.Today.Year;
        //                int century = currentYear - (currentYear % 100);
        //                ValidatorHelper.AddExpandoAttribute(validator, id, "century", century.ToString(NumberFormatInfo.InvariantInfo), false);
        //            }
        //        }
        //    }
        //}

        public static void DoBaseValidatorAddAttributes(WhidbeyBaseValidator validator, IBaseValidatorAccessor validatorAccessor, HtmlTextWriter writer)
        {
            bool disabled = !validator.Enabled;

            if (disabled)
            {
                validator.Enabled = true;
            }

            try {
                if (validatorAccessor.RenderUpLevel)
                {
                    validatorAccessor.EnsureID();
                    string id = validator.ClientID;

                    if (validator.ControlToValidate.Length > 0)
                    {
                        AddExpandoAttribute(validator, id, "controltovalidate", validatorAccessor.GetControlRenderID(validator.ControlToValidate));
                    }
                    if (validator.SetFocusOnError)
                    {
                        AddExpandoAttribute(validator, id, "focusOnError", "t", false);
                    }
                    if (validator.ErrorMessage.Length > 0)
                    {
                        AddExpandoAttribute(validator, id, "errormessage", validator.ErrorMessage);
                    }
                    ValidatorDisplay display = validator.Display;
                    if (display != ValidatorDisplay.Static)
                    {
                        AddExpandoAttribute(validator, id, "display", PropertyConverter.EnumToString(typeof(ValidatorDisplay), display), false);
                    }
                    if (!validator.IsValid)
                    {
                        AddExpandoAttribute(validator, id, "isvalid", "False", false);
                    }
                    if (disabled)
                    {
                        AddExpandoAttribute(validator, id, "enabled", "False", false);
                    }
                    if (validator.ValidationGroup.Length > 0)
                    {
                        AddExpandoAttribute(validator, id, "validationGroup", validator.ValidationGroup);
                    }
                }

                DoWebControlAddAttributes(validator, validatorAccessor, writer);
            }
            finally {
                if (disabled)
                {
                    validator.Enabled = false;
                }
            }
        }
Esempio n. 13
0
        public RangeClientValidationRule(string errorMessage, object minValue, object maxValue, Type operandType)
        {
            // Since standard aps.net validation library supports only Int32, Double, String and DateTime types
            // then we will not try to validate other types on client side
            ValidationDataType?validationDataType = GetValidationDataType(operandType);

            if (!validationDataType.HasValue)
            {
                return;
            }

            ErrorMessage = errorMessage;

            EvaluationFunction = "RangeValidatorEvaluateIsValid";

            Parameters["maximumvalue"] = maxValue;
            Parameters["minimumvalue"] = minValue;

            Parameters["type"] = PropertyConverter.EnumToString(typeof(ValidationDataType), validationDataType.Value);

            NumberFormatInfo numberFormat = NumberFormatInfo.CurrentInfo;

            if (validationDataType.Value == ValidationDataType.Double)
            {
                Parameters["decimalchar"] = numberFormat.NumberDecimalSeparator;
            }
            else if (validationDataType.Value == ValidationDataType.Date)
            {
                int currentYear = DateTime.Today.Year;
                int century     = currentYear - (currentYear % 100);

                DateTimeFormatInfo dateFormat = DateTimeFormatInfo.CurrentInfo;
                Debug.Assert(dateFormat != null, "dateFormat != null");

                string shortPattern = dateFormat.ShortDatePattern;
                string dateElementOrder;
                string cutoffYear = dateFormat.Calendar.TwoDigitYearMax.ToString(NumberFormatInfo.InvariantInfo);
                if (shortPattern.IndexOf('y') < shortPattern.IndexOf('M'))
                {
                    dateElementOrder = "ymd";
                }
                else if (shortPattern.IndexOf('M') < shortPattern.IndexOf('d'))
                {
                    dateElementOrder = "mdy";
                }
                else
                {
                    dateElementOrder = "dmy";
                }

                Parameters["dateorder"]  = dateElementOrder;
                Parameters["cutoffyear"] = cutoffYear;
                Parameters["century"]    = century.ToString(NumberFormatInfo.InvariantInfo);
            }
        }
Esempio n. 14
0
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            if (base.RenderUplevel)
            {
                ValidationDataType enumValue = this.Type;
                if (enumValue != ValidationDataType.String)
                {
                    string         clientID = this.ClientID;
                    HtmlTextWriter writer2  = base.EnableLegacyRendering ? writer : null;
                    base.AddExpandoAttribute(writer2, clientID, "type", PropertyConverter.EnumToString(typeof(ValidationDataType), enumValue), false);
                    NumberFormatInfo currentInfo = NumberFormatInfo.CurrentInfo;
                    switch (enumValue)
                    {
                    case ValidationDataType.Double:
                    {
                        string numberDecimalSeparator = currentInfo.NumberDecimalSeparator;
                        base.AddExpandoAttribute(writer2, clientID, "decimalchar", numberDecimalSeparator);
                        return;
                    }

                    case ValidationDataType.Currency:
                    {
                        string currencyDecimalSeparator = currentInfo.CurrencyDecimalSeparator;
                        base.AddExpandoAttribute(writer2, clientID, "decimalchar", currencyDecimalSeparator);
                        string currencyGroupSeparator = currentInfo.CurrencyGroupSeparator;
                        if (currencyGroupSeparator[0] == '\x00a0')
                        {
                            currencyGroupSeparator = " ";
                        }
                        base.AddExpandoAttribute(writer2, clientID, "groupchar", currencyGroupSeparator);
                        base.AddExpandoAttribute(writer2, clientID, "digits", currentInfo.CurrencyDecimalDigits.ToString(NumberFormatInfo.InvariantInfo), false);
                        int currencyGroupSize = GetCurrencyGroupSize(currentInfo);
                        if (currencyGroupSize > 0)
                        {
                            base.AddExpandoAttribute(writer2, clientID, "groupsize", currencyGroupSize.ToString(NumberFormatInfo.InvariantInfo), false);
                            return;
                        }
                        break;
                    }

                    case ValidationDataType.Date:
                    {
                        base.AddExpandoAttribute(writer2, clientID, "dateorder", GetDateElementOrder(), false);
                        base.AddExpandoAttribute(writer2, clientID, "cutoffyear", CutoffYear.ToString(NumberFormatInfo.InvariantInfo), false);
                        int year = DateTime.Today.Year;
                        base.AddExpandoAttribute(writer2, clientID, "century", (year - (year % 100)).ToString(NumberFormatInfo.InvariantInfo), false);
                        break;
                    }
                    }
                }
            }
        }
Esempio n. 15
0
        /// <include file='doc\BaseValidator.uex' path='docs/doc[@for="BaseValidator.AddAttributesToRender"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    <para>Adds the attributes of this control to the output stream for rendering on the
        ///       client.</para>
        /// </devdoc>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            // Validators do not render the "disabled" attribute, instead they are invisible when disabled.
            bool disabled = !Enabled;

            if (disabled)
            {
                Enabled = true;
            }
            base.AddAttributesToRender(writer);

            if (RenderUplevel)
            {
                // We always want validators to have an id on the client, so if it's null, write it here.
                // Otherwise, base.RenderAttributes takes care of it.
                // REVIEW: this is a bit hacky.
                if (ID == null)
                {
                    writer.AddAttribute("id", ClientID);
                }

                if (ControlToValidate.Length > 0)
                {
                    writer.AddAttribute("controltovalidate", GetControlRenderID(ControlToValidate));
                }
                if (ErrorMessage.Length > 0)
                {
                    writer.AddAttribute("errormessage", ErrorMessage, true);
                }
                ValidatorDisplay display = Display;
                if (display != ValidatorDisplay.Static)
                {
                    writer.AddAttribute("display", PropertyConverter.EnumToString(typeof(ValidatorDisplay), display));
                }
                if (!IsValid)
                {
                    writer.AddAttribute("isvalid", "False");
                }
                if (disabled)
                {
                    writer.AddAttribute("enabled", "False");
                }
            }
            if (disabled)
            {
                Enabled = false;
            }
        }
        protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
        {
            // Setting SetFocusOnError before calling the base AddAttributesToRender because
            // the AddAttributesToRender is going to check for "SetFocusOnError" value
            base.SetFocusOnError = false; // Because we have many fields to check!

            base.AddAttributesToRender(writer);

            if (this.RenderUplevel)
            {
                string clientID = this.ClientID;

                Page.ClientScript.RegisterExpandoAttribute(clientID, "evaluationfunction", "MultipleFieldsValidatorEvaluateIsValid");
                Page.ClientScript.RegisterExpandoAttribute(clientID, "controlstovalidate", this.GenerateClientSideControlsToValidate());
                Page.ClientScript.RegisterExpandoAttribute(clientID, "condition", PropertyConverter.EnumToString(typeof(Conditions), Condition));
            }
        }
Esempio n. 17
0
        /// <include file='doc\RangeValidator.uex' path='docs/doc[@for="RangeValidator.ControlPropertiesValid"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    This is a check of properties to determine any errors made by the developer
        /// </devdoc>
        protected override bool ControlPropertiesValid()
        {
            // Check the control values can be converted to data type
            string maximumValue = MaximumValue;

            if (!CanConvert(maximumValue, Type))
            {
                throw new HttpException(
                          HttpRuntime.FormatResourceString(
                              SR.Validator_value_bad_type,
                              new string [] {
                    maximumValue,
                    "MaximumValue",
                    ID,
                    PropertyConverter.EnumToString(typeof(ValidationDataType), Type)
                }));
            }
            string minumumValue = MinimumValue;

            if (!CanConvert(minumumValue, Type))
            {
                throw new HttpException(
                          HttpRuntime.FormatResourceString(
                              SR.Validator_value_bad_type,
                              new string [] {
                    minumumValue,
                    "MinimumValue",
                    ID,
                    PropertyConverter.EnumToString(typeof(ValidationDataType), Type)
                }));
            }
            // Check for overlap.
            if (Compare(minumumValue, maximumValue, ValidationCompareOperator.GreaterThan, Type))
            {
                throw new HttpException(
                          HttpRuntime.FormatResourceString(
                              SR.Validator_range_overalap,
                              new string [] {
                    maximumValue,
                    minumumValue,
                    ID,
                }));
            }
            return(base.ControlPropertiesValid());
        }
Esempio n. 18
0
 protected virtual void RegisterClientValidator(Page page, clientValidatorInfo validatorInfo, int number)
 {
     AddExpandoAttribute(page, null, validatorInfo.clientID, "controltovalidate", validatorInfo.controlToValidate);
     AddExpandoAttribute(page, null, validatorInfo.clientID, "focusOnError", "t", false);
     AddExpandoAttribute(page, null, validatorInfo.clientID, "errormessage", ErrorMessageInSummary + number.ToString(" (#0)"));
     if (validatorInfo.display != ValidatorDisplay.Static)
     {
         AddExpandoAttribute(page, null, validatorInfo.clientID, "display", PropertyConverter.EnumToString(typeof(ValidatorDisplay), validatorInfo.display), false);
     }
     if (!validatorInfo.isValid)
     {
         AddExpandoAttribute(page, null, validatorInfo.clientID, "isvalid", "False", false);
     }
     if (validatorInfo.validationGroup.Length > 0)
     {
         AddExpandoAttribute(page, null, validatorInfo.clientID, "validationGroup", validatorInfo.validationGroup);
     }
 }
Esempio n. 19
0
        /// <devdoc>
        ///
        /// </devdoc>
        private void ValidateValues()
        {
            // Check the control values can be converted to data type
            string maximumValue = MaximumValue;

            if (!CanConvert(maximumValue, Type, CultureInvariantValues))
            {
                throw new HttpException(
                          SR.GetString(SR.Validator_value_bad_type,
                                       new string [] {
                    maximumValue,
                    "MaximumValue",
                    ID,
                    PropertyConverter.EnumToString(typeof(ValidationDataType), Type)
                }));
            }
            string minumumValue = MinimumValue;

            if (!CanConvert(minumumValue, Type, CultureInvariantValues))
            {
                throw new HttpException(
                          SR.GetString(SR.Validator_value_bad_type,
                                       new string [] {
                    minumumValue,
                    "MinimumValue",
                    ID,
                    PropertyConverter.EnumToString(typeof(ValidationDataType), Type)
                }));
            }
            // Check for overlap.
            if (Compare(minumumValue, CultureInvariantValues,
                        maximumValue, CultureInvariantValues,
                        ValidationCompareOperator.GreaterThan, Type))
            {
                throw new HttpException(
                          SR.GetString(SR.Validator_range_overalap,
                                       new string [] {
                    maximumValue,
                    minumumValue,
                    ID,
                }));
            }
        }
        /// <include file='doc\basecomparevalidator.uex' path='docs/doc[@for="BaseCompareValidator.AddAttributesToRender"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    AddAttributesToRender method
        /// </devdoc>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            if (RenderUplevel)
            {
                ValidationDataType type = Type;
                if (type != ValidationDataType.String)
                {
                    writer.AddAttribute("type", PropertyConverter.EnumToString(typeof(ValidationDataType), type));

                    NumberFormatInfo info = NumberFormatInfo.CurrentInfo;
                    if (type == ValidationDataType.Double)
                    {
                        string decimalChar = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
                        writer.AddAttribute("decimalchar", decimalChar);
                    }
                    else if (type == ValidationDataType.Currency)
                    {
                        string decimalChar = info.CurrencyDecimalSeparator;
                        writer.AddAttribute("decimalchar", decimalChar);
                        string groupChar = info.CurrencyGroupSeparator;
                        // Map non-break space onto regular space for parsing
                        if (groupChar[0] == 160)
                        {
                            groupChar = " ";
                        }
                        writer.AddAttribute("groupchar", groupChar);
                        int digits = info.CurrencyDecimalDigits;
                        writer.AddAttribute("digits", digits.ToString(NumberFormatInfo.InvariantInfo));
                    }
                    else if (type == ValidationDataType.Date)
                    {
                        writer.AddAttribute("dateorder", GetDateElementOrder());
                        writer.AddAttribute("cutoffyear", CutoffYear.ToString());
                        int currentYear = DateTime.Today.Year;
                        int century     = currentYear - (currentYear % 100);
                        writer.AddAttribute("century", century.ToString());
                    }
                }
            }
        }
Esempio n. 21
0
 // <summary>
 //  AddAttributesToRender method
 // </summary>
 /// <include file='doc\CompareValidator.uex' path='docs/doc[@for="CompareValidator.AddAttributesToRender"]/*' />
 /// <internalonly/>
 /// <devdoc>
 ///    <para>Adds the attributes of this control to the output stream for rendering on the
 ///       client.</para>
 /// </devdoc>
 protected override void AddAttributesToRender(HtmlTextWriter writer)
 {
     base.AddAttributesToRender(writer);
     if (RenderUplevel)
     {
         writer.AddAttribute("evaluationfunction", "CompareValidatorEvaluateIsValid");
         if (ControlToCompare.Length > 0)
         {
             writer.AddAttribute("controltocompare", GetControlRenderID(ControlToCompare));
             writer.AddAttribute("controlhookup", GetControlRenderID(ControlToCompare));
         }
         if (ValueToCompare.Length > 0)
         {
             writer.AddAttribute("valuetocompare", ValueToCompare);
         }
         if (Operator != ValidationCompareOperator.Equal)
         {
             writer.AddAttribute("operator", PropertyConverter.EnumToString(typeof(ValidationCompareOperator), Operator));
         }
     }
 }
Esempio n. 22
0
        /////////////////////////////////////////////////////////////////////
        // Helper function adopted from WebForms RangeValidator
        /////////////////////////////////////////////////////////////////////

        protected override bool ControlPropertiesValid()
        {
            // Check if the control values can be converted to data type
            String maximumValue = MaximumValue;

            if (!WebCntrls.BaseCompareValidator.CanConvert(maximumValue, Type))
            {
                throw new ArgumentException(SR.GetString(
                                                SR.Validator_ValueBadType,
                                                maximumValue,
                                                "MaximumValue",
                                                ID,
                                                PropertyConverter.EnumToString(
                                                    typeof(ValidationDataType), Type)
                                                ));
            }
            String minumumValue = MinimumValue;

            if (!WebCntrls.BaseCompareValidator.CanConvert(minumumValue, Type))
            {
                throw new ArgumentException(SR.GetString(
                                                SR.Validator_ValueBadType,
                                                minumumValue,
                                                "MinimumValue",
                                                ID,
                                                PropertyConverter.EnumToString(
                                                    typeof(ValidationDataType), Type)
                                                ));
            }
            // Check for overlap.
            if (WebBaseCompareValidator.Compare(minumumValue, maximumValue,
                                                ValidationCompareOperator.GreaterThan, Type))
            {
                throw new ArgumentException(SR.GetString(
                                                SR.RangeValidator_RangeOverlap, maximumValue,
                                                minumumValue, ID));
            }
            return(base.ControlPropertiesValid());
        }
        /// <summary>
        /// Right before the control is going to render, I add my client-side validation
        /// script if the browser is capable of handling it.
        /// </summary>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (RenderUplevel)
            {
                string script = "\r\n<script language=\"javascript\">\r\n" +
                                "	function RequiredIfValidatorEvaluateIsValid(val){\r\n"+
                                "		if (val.controltocompare != \"\") {\r\n"+
                                //"           debugger;\r\n" +
                                "           var control = document.getElementById(val.controltocompare);\r\n" +
                                "           if((control.type == 'radio' || control.type == 'checkbox') \r\n" +
                                "               && ((val.triggervalue == 'true' && control.checked) ||(val.triggervalue == 'false' && !control.checked ))) {\r\n" +
                                "				return RequiredFieldValidatorEvaluateIsValid(val);\r\n"+
                                "			}\r\n"+
                                "			else if (val.triggervalueoperator == 'EqualTo' && control.value == val.triggervalue) {\r\n"+
                                "				return RequiredFieldValidatorEvaluateIsValid(val);\r\n"+
                                "			} else if (val.triggervalueoperator == 'NotEqualTo' && control.value != val.triggervalue) {\r\n"+
                                "				return RequiredFieldValidatorEvaluateIsValid(val);\r\n"+
                                "			} else {\r\n"+
                                "				return true;\r\n"+
                                "			}\r\n"+
                                "		} else {\r\n"+
                                "			return true;\r\n"+
                                "		}\r\n"+
                                "	}\r\n"+
                                "</script>\r\n";

                this.RegisterClientScriptBlock(this.GetType(), "__RequiredIfValidatorMethod", script, false);


                this.RegisterExpandoAttribute(this.ClientID, "initialvalue", InitialValue, false);
                this.RegisterExpandoAttribute(this.ClientID, "evaluationfunction", "RequiredIfValidatorEvaluateIsValid", false);
                this.RegisterExpandoAttribute(this.ClientID, "controltocompare", this.GetControlRenderID(ControlToCompare), false);
                this.RegisterExpandoAttribute(this.ClientID, "triggervalue", TriggerValue, false);
                this.RegisterExpandoAttribute(this.ClientID, "triggervalueoperator", PropertyConverter.EnumToString(typeof(Operator), this.TriggerValueOperator), false);
            }
        }
Esempio n. 24
0
        public string ToString(IFormatProvider formatProvider)
        {
            string s = String.Empty;

            if (IsEmpty)
            {
                return(s);
            }

            switch (type)
            {
            case FontSize.AsUnit:
                s = value.ToString(formatProvider);
                break;

            case FontSize.XXSmall:
                s = "XX-Small";
                break;

            case FontSize.XSmall:
                s = "X-Small";
                break;

            case FontSize.XLarge:
                s = "X-Large";
                break;

            case FontSize.XXLarge:
                s = "XX-Large";
                break;

            default:
                s = PropertyConverter.EnumToString(typeof(FontSize), type);
                break;
            }
            return(s);
        }
 protected override void AddAttributesToRender(HtmlTextWriter writer)
 {
     if (this.renderUplevel)
     {
         base.EnsureID();
         string         clientID = this.ClientID;
         HtmlTextWriter writer2  = base.EnableLegacyRendering ? writer : null;
         if (this.HeaderText.Length > 0)
         {
             BaseValidator.AddExpandoAttribute(this, writer2, clientID, "headertext", this.HeaderText, true);
         }
         if (this.ShowMessageBox)
         {
             BaseValidator.AddExpandoAttribute(this, writer2, clientID, "showmessagebox", "True", false);
         }
         if (!this.ShowSummary)
         {
             BaseValidator.AddExpandoAttribute(this, writer2, clientID, "showsummary", "False", false);
         }
         if (this.DisplayMode != ValidationSummaryDisplayMode.BulletList)
         {
             BaseValidator.AddExpandoAttribute(this, writer2, clientID, "displaymode", PropertyConverter.EnumToString(typeof(ValidationSummaryDisplayMode), this.DisplayMode), false);
         }
         if (this.ValidationGroup.Length > 0)
         {
             BaseValidator.AddExpandoAttribute(this, writer2, clientID, "validationGroup", this.ValidationGroup, true);
         }
     }
     base.AddAttributesToRender(writer);
 }
        private void ValidateValues()
        {
            string maximumValue = this.MaximumValue;

            if (!BaseCompareValidator.CanConvert(maximumValue, base.Type, base.CultureInvariantValues))
            {
                throw new HttpException(System.Web.SR.GetString("Validator_value_bad_type", new string[] { maximumValue, "MaximumValue", this.ID, PropertyConverter.EnumToString(typeof(ValidationDataType), base.Type) }));
            }
            string minimumValue = this.MinimumValue;

            if (!BaseCompareValidator.CanConvert(minimumValue, base.Type, base.CultureInvariantValues))
            {
                throw new HttpException(System.Web.SR.GetString("Validator_value_bad_type", new string[] { minimumValue, "MinimumValue", this.ID, PropertyConverter.EnumToString(typeof(ValidationDataType), base.Type) }));
            }
            if (BaseCompareValidator.Compare(minimumValue, base.CultureInvariantValues, maximumValue, base.CultureInvariantValues, ValidationCompareOperator.GreaterThan, base.Type))
            {
                throw new HttpException(System.Web.SR.GetString("Validator_range_overalap", new string[] { maximumValue, minimumValue, this.ID }));
            }
        }
Esempio n. 27
0
 public void EnumToStringWrongBaseType()
 {
     PropertyConverter.EnumToString(typeof(TestEnum), "foo");
 }
Esempio n. 28
0
 public void StaticMethods_Deny_Unrestricted()
 {
     Assert.AreEqual(SecurityAction.Demand, PropertyConverter.EnumFromString(typeof(SecurityAction), "Demand"), "EnumFromString");
     Assert.AreEqual("Demand", PropertyConverter.EnumToString(typeof(SecurityAction), SecurityAction.Demand), "EnumToString");
     Assert.AreEqual(String.Empty, PropertyConverter.ObjectFromString(typeof(string), null, String.Empty), "ObjectFromString");
 }
        /// <internalonly/>
        /// <devdoc>
        ///    AddAttributesToRender method.
        /// </devdoc>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            if (renderUplevel)
            {
                // We always want validation cotnrols to have an id on the client
                EnsureID();
                string id = ClientID;

                // DevDiv 33149: A backward compat. switch for Everett rendering
                HtmlTextWriter expandoAttributeWriter = (EnableLegacyRendering || IsUnobtrusive) ? writer : null;

                if (IsUnobtrusive)
                {
                    Attributes["data-valsummary"] = "true";
                }

                if (HeaderText.Length > 0)
                {
                    BaseValidator.AddExpandoAttribute(this, expandoAttributeWriter, id, "headertext", HeaderText, true);
                }
                if (ShowMessageBox)
                {
                    BaseValidator.AddExpandoAttribute(this, expandoAttributeWriter, id, "showmessagebox", "True", false);
                }
                if (!ShowSummary)
                {
                    BaseValidator.AddExpandoAttribute(this, expandoAttributeWriter, id, "showsummary", "False", false);
                }
                if (DisplayMode != ValidationSummaryDisplayMode.BulletList)
                {
                    BaseValidator.AddExpandoAttribute(this, expandoAttributeWriter, id, "displaymode", PropertyConverter.EnumToString(typeof(ValidationSummaryDisplayMode), DisplayMode), false);
                }
                if (ValidationGroup.Length > 0)
                {
                    BaseValidator.AddExpandoAttribute(this, expandoAttributeWriter, id, "validationGroup", ValidationGroup, true);
                }
            }

            base.AddAttributesToRender(writer);
        }
        /// <internalonly/>
        /// <devdoc>
        ///    <para>Adds the attributes of this control to the output stream for rendering on the
        ///       client.</para>
        /// </devdoc>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            // Validators do not render the "disabled" attribute, instead they are invisible when disabled.
            bool disabled = !Enabled;

            if (disabled)
            {
                Enabled = true;
            }

            try {
                if (RenderUplevel)
                {
                    // We always want validators to have an id on the client
                    EnsureID();
                    string id = ClientID;

                    // DevDiv Schedule 33075: Expando attributes are added through client-side JavaScript

                    // DevDiv 33149: A backward compat. switch for Everett rendering
                    HtmlTextWriter expandoAttributeWriter = (EnableLegacyRendering || IsUnobtrusive) ? writer : null;

                    if (IsUnobtrusive)
                    {
                        Attributes["data-val"] = "true";
                    }

                    if (ControlToValidate.Length > 0)
                    {
                        AddExpandoAttribute(expandoAttributeWriter, id, "controltovalidate", GetControlRenderID(ControlToValidate));
                    }
                    if (SetFocusOnError)
                    {
                        AddExpandoAttribute(expandoAttributeWriter, id, "focusOnError", "t", false);
                    }
                    if (ErrorMessage.Length > 0)
                    {
                        AddExpandoAttribute(expandoAttributeWriter, id, "errormessage", ErrorMessage);
                    }
                    ValidatorDisplay display = Display;
                    if (display != ValidatorDisplay.Static)
                    {
                        AddExpandoAttribute(expandoAttributeWriter, id, "display", PropertyConverter.EnumToString(typeof(ValidatorDisplay), display), false);
                    }
                    if (!IsValid)
                    {
                        AddExpandoAttribute(expandoAttributeWriter, id, "isvalid", "False", false);
                    }
                    if (disabled)
                    {
                        AddExpandoAttribute(expandoAttributeWriter, id, "enabled", "False", false);
                    }
                    if (ValidationGroup.Length > 0)
                    {
                        AddExpandoAttribute(expandoAttributeWriter, id, "validationGroup", ValidationGroup);
                    }
                }

                base.AddAttributesToRender(writer);
            }
            finally {
                // If exception happens above, we can still reset the property if needed
                if (disabled)
                {
                    Enabled = false;
                }
            }
        }