Beispiel #1
0
        protected override void OnPreRender(EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.LabelResourceKey) || !string.IsNullOrEmpty(this.LabelText))
            {
                this.lbl = Utilities.CreateLabel(this.LabelResourceKey, this.LabelText);
                this.Controls.Add(lbl);
            }

            if (this.IsRequired)
            {
                this.reqValidator = Utilities.CreateRequiredFieldValidator(this.ID, this.ValidationGroup);
                reqValidator.Style.Add("padding", "0px 5px");
                this.Controls.Add(reqValidator);
            }

            if (!this.PropertiesLoaded)
            {
                if (this.ShowPopover)
                {
                    Utilities.AddPopoverAttributes(this.ID, this.Attributes, this.PopoverDiraction, PopoverTriggers.Focus, this.PopoverTextResourceKey);
                }

                this.CssClass = string.Concat(this.CssClass, " ", "form-control");
                this.Attributes.Add("aria-describedby", this.ID + "-addon");

                this.PropertiesLoaded = true;
            }

            base.OnPreRender(e);
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (!string.IsNullOrEmpty(this.LabelResourceKey) || !string.IsNullOrEmpty(this.LabelText))
            {
                this.lbl = Utilities.CreateLabel(this.LabelResourceKey, this.LabelText);
                this.Controls.Add(lbl);
            }

            if (this.IsRequired)
            {
                this.reqValidator = string.IsNullOrEmpty(this.RequiredErrorMessage) ? Utilities.CreateRequiredFieldValidator(this.ID, this.ValidationGroup) : Utilities.CreateRequiredFieldValidator(this.ID, this.ValidationGroup, this.RequiredErrorMessage);
                this.Controls.Add(reqValidator);
            }

            if (!this.PropertiesLoaded)
            {
                if (this.ShowPopover)
                {
                    Utilities.AddPopoverAttributes(this.ID, this.Attributes, this.PopoverDiraction, PopoverTriggers.Focus, this.PopoverTextResourceKey);
                }

                this.CssClass = string.Concat(this.CssClass, " ", this.ControlSize.ToString().ToLower());

                this.PropertiesLoaded = true;
            }

            if (this.IncludeDefaultItem && !this.ContainsDefaultItem)
            {
                this.Items.Insert(0, new ListItem(Resources.Choose, ""));
                this.SelectedIndex = 0;
            }

            if (this.Disabled && this.Attributes["disabled"] == null)
            {
                this.Attributes.Add("disabled", "disabled");
            }
            else if (!this.Disabled && this.Attributes["disabled"] != null)
            {
                this.Attributes.Remove("disabled");
            }

            if (this.AddonType.HasValue && this.AddonType.Value == AddonTypes.RadioButton)
            {
                this.addonRadioButton.Checked = this.AddonChecked;
            }

            //this.ApplyOnPreRendarFeatures();
        }
Beispiel #3
0
        protected override void OnPreRender(EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.LabelResourceKey) || !string.IsNullOrEmpty(this.LabelText))
            {
                this.lbl = Utilities.CreateLabel(this.LabelResourceKey, this.LabelText);
                this.Controls.Add(lbl);
            }

            if (this.IsRequired)
            {
                this.reqValidator = Utilities.CreateRequiredFieldValidator(this.ID, this.ValidationGroup);
                this.Controls.Add(reqValidator);
            }

            if (!this.PropertiesLoaded)
            {
                this.PropertiesLoaded = true;
            }

            base.OnPreRender(e);
        }
Beispiel #4
0
        protected override void OnPreRender(EventArgs e)
        {
            #region Label
            if (!string.IsNullOrEmpty(this.LabelResourceKey) || !string.IsNullOrEmpty(this.LabelText))
            {
                this.lbl = Utilities.CreateLabel(this.LabelResourceKey, this.LabelText);
                this.Controls.Add(lbl);
            }
            #endregion

            #region Validations
            if (this.IsRequired)
            {
                this.reqValidator = Utilities.CreateRequiredFieldValidator(this.ID, this.ValidationGroup);
                this.Controls.Add(reqValidator);
            }

            if (this.DataType != TextBoxDataTypes.String)
            {
                string validationExpression = string.Empty;
                switch (this.DataType)
                {
                case TextBoxDataTypes.Email: validationExpression = @"\w+([-+.]\w+)*@\w+([-.]\w{2,3})+"; break;

                case TextBoxDataTypes.NationalID:
                    validationExpression = "(2|3)[0-9][0-9][0-1][1-9][0-3][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]";
                    this.MaxLength       = 14;
                    break;

                case TextBoxDataTypes.Year:
                    //validate that the year number is four numbers and starts with 2.
                    validationExpression = @"2\d{3}";
                    this.MaxLength       = 4;
                    break;

                case TextBoxDataTypes.Username:
                    validationExpression = "^[a-zA-Z0-9_]{4,40}$";
                    break;

                case TextBoxDataTypes.Alphapet:
                    validationExpression = "^[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FFa-zA-Z_⁠⁠⁠أإءئؤآي]+[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FFa-zA-Z-_⁠⁠⁠أإءئؤآي]*$";
                    break;

                case TextBoxDataTypes.Int:
                case TextBoxDataTypes.Double:
                case TextBoxDataTypes.Mobile:
                case TextBoxDataTypes.Phone:
                    validationExpression = "^\\d+$" + (this.DataType == TextBoxDataTypes.Double ? "|^-?\\d*\\.\\d+$" : "");
                    if (this.DataType == TextBoxDataTypes.Mobile)
                    {
                        validationExpression = "^01[0125]{1}[0-9]{7,11}";
                        this.MaxLength       = 11;
                    }
                    else if (this.DataType == TextBoxDataTypes.Phone)
                    {
                        validationExpression = "[+-]?[0-9]{5,11}";
                        this.MaxLength       = 11;
                    }
                    if (this.MaxLength == 0)
                    {
                        if (this.DataType == TextBoxDataTypes.Double)
                        {
                            this.MaxLength = 10;
                        }
                        else if (this.DataType == TextBoxDataTypes.Int)
                        {
                            this.MaxLength = 7;
                        }
                    }
                    break;
                }
                this.regValidator = Utilities.CreateRegularExpressionValidator(this.ID, this.ValidationGroup, validationExpression, "InvalidValue");
                this.Controls.Add(regValidator);
            }

            if (!string.IsNullOrEmpty(this.MinValue) && !string.IsNullOrEmpty(this.MaxValue))
            {
                this.rngValidator = Utilities.CreateRangeValidator(this.ID, this.ValidationGroup, this.DataType == TextBoxDataTypes.Int ? ValidationDataType.Integer : ValidationDataType.Double, this.MinValue, this.MaxValue);
                this.Controls.Add(rngValidator);
            }
            else if (!string.IsNullOrEmpty(this.MinValue) && string.IsNullOrEmpty(this.MaxValue))
            {
                this.cmprValidator = Utilities.CreateCompareValidator(this.ID, this.ValidationGroup, this.DataType == TextBoxDataTypes.Int ? ValidationDataType.Integer : ValidationDataType.Double, this.MinValue, ValidationCompareOperator.GreaterThanEqual, "CompareValidatorGreaterThanErrorMessage");
                this.Controls.Add(cmprValidator);
            }
            else if (string.IsNullOrEmpty(this.MinValue) && !string.IsNullOrEmpty(this.MaxValue))
            {
                this.cmprValidator = Utilities.CreateCompareValidator(this.ID, this.ValidationGroup, this.DataType == TextBoxDataTypes.Int ? ValidationDataType.Integer : ValidationDataType.Double, this.MaxValue, ValidationCompareOperator.LessThanEqual, "CompareValidatorLessThanErrorMessage");
                this.Controls.Add(cmprValidator);
            }

            #endregion
            #region AutoCompelete
            if (this.IsAutoCombelete)
            {
                this.hdjson = new CHiddenField();
                this.Controls.Add(hdjson);
            }
            #endregion
            #region Properties

            if (!this.PropertiesLoaded)
            {
                if (this.ShowPopover)
                {
                    Utilities.AddPopoverAttributes(this.ID, this.Attributes, this.PopoverDiraction, PopoverTriggers.Focus, this.PopoverTextResourceKey);
                }

                if (this.IsAutoCombelete)
                {
                    this.CssClass = string.Concat(this.CssClass, "auto");
                }

                if (this.TextMode == TextBoxMode.MultiLine && this.MaxLength > 0)
                {
                    this.Attributes.Add("maxlength", this.MaxLength.ToString());
                }


                if (this.DataType != TextBoxDataTypes.String)
                {
                    switch (this.DataType)
                    {
                    case TextBoxDataTypes.Double:
                        this.Attributes.Add("data-type", this.DataType.ToString().ToLower());
                        break;

                    case TextBoxDataTypes.Int:
                    case TextBoxDataTypes.Mobile:
                    case TextBoxDataTypes.Phone:
                    case TextBoxDataTypes.NationalID:
                        this.Attributes.Add("data-type", TextBoxDataTypes.Int.ToString().ToLower());
                        break;

                    case TextBoxDataTypes.Year:
                        this.Attributes.Add("data-type", TextBoxDataTypes.Int.ToString().ToLower());
                        if (this.DefaultData != TextBoxDefaultData.empty)
                        {
                            this.Text = DateTime.Now.Year.ToString();
                        }

                        break;
                    }
                }


                if (!string.IsNullOrEmpty(this.PlaceholderResourceKey))
                {
                    this.Attributes.Add("placeholder", Resources.ResourceManager.GetString(this.PlaceholderResourceKey));
                }

                this.CssClass = string.Concat(this.CssClass, " ", this.ControlSize.ToString().ToLower());

                if (this.ShowInAddon)
                {
                    this.CssClass = string.Concat(this.CssClass, " form-control");
                }

                this.PropertiesLoaded = true;
            }

            if (this.Disabled && this.Attributes["disabled"] == null)
            {
                this.Attributes.Add("disabled", "disabled");
            }
            else if (!this.Disabled && this.Attributes["disabled"] != null)
            {
                this.Attributes.Remove("disabled");
            }

            if (this.AddonType.HasValue && this.AddonType.Value == AddonTypes.RadioButton)
            {
                this.addonRadioButton.Checked = this.AddonChecked;
            }

            #endregion

            base.OnPreRender(e);
        }