Example #1
0
        /// <summary>
        /// 创建子控件方法
        /// </summary>
        protected override void CreateChildControls()
        {
            if (this.ViewState[IS_ADDED_LIST_ITEM] == null)
            {
                if (IsRequired)
                {
                    this.Attributes.Add("IsRequired", "True");
                }
                this.Attributes.Add("MyInputType", "CheckBoxList");
                this.Attributes.Add("ShowErrorType", ShowErrorType.ToString());
                AddDropDownItem();                              //添加列表项目重载
            }

            base.CreateChildControls();
        }
Example #2
0
        /// <summary>
        /// 改写OnPreRender
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            //添加默认样式表
            if (string.IsNullOrWhiteSpace(this.CssClass))
            {
                this.CssClass = "myTextBox";
            }
            else if (this.CssClass.IndexOf("myTextBox") == -1)
            {
                this.CssClass += " myTextBox";
            }

            if (IsRequired)
            {
                if (this.Attributes["IsRequired"] == null)
                {
                    this.Attributes.Add("IsRequired", "True");
                }
                else
                {
                    this.Attributes["IsRequired"] = "true";
                }
            }
            if (MinLength > 0)
            {
                if (this.Attributes["MinLength"] == null)
                {
                    this.Attributes.Add("MinLength", MinLength.ToString());
                }
                else
                {
                    this.Attributes["MinLength"] = MinLength.ToString();
                }
            }
            if (!string.IsNullOrWhiteSpace(WatermarkText))
            {
                if (this.Attributes["placeholder"] == null)
                {
                    this.Attributes.Add("placeholder", WatermarkText);
                }
                else
                {
                    this.Attributes["placeholder"] = WatermarkText;
                }
            }
            if (!string.IsNullOrWhiteSpace(ValidationExpression))
            {
                if (this.Attributes["ValidationExpression"] == null)
                {
                    this.Attributes.Add("ValidationExpression", ValidationExpression);
                }
                else
                {
                    this.Attributes["ValidationExpression"] = ValidationExpression;
                }
            }
            if (IsFilterSqlChars)
            {
                if (this.Attributes["IsFilterSqlChars"] == null)
                {
                    this.Attributes.Add("IsFilterSqlChars", "True");
                }
                else
                {
                    this.Attributes["IsFilterSqlChars"] = "True";
                }
            }
            if (IsFilterSpecialChars)
            {
                if (this.Attributes["IsFilterSpecialChars"] == null)
                {
                    this.Attributes.Add("IsFilterSpecialChars", "True");
                }
                else
                {
                    this.Attributes["IsFilterSpecialChars"] = "True";
                }
            }

            if (this.Attributes["MyInputType"] == null)
            {
                this.Attributes.Add("MyInputType", this.GetType().Name);
            }
            else
            {
                this.Attributes["MyInputType"] = this.GetType().Name;
            }

            if (this.Attributes["ShowErrorType"] == null)
            {
                this.Attributes.Add("ShowErrorType", ShowErrorType.ToString());
            }
            else
            {
                this.Attributes["ShowErrorType"] = ShowErrorType.ToString();
            }

            if (this.TextMode == System.Web.UI.WebControls.TextBoxMode.MultiLine)
            {
                this.Attributes.Add("TextAreaMaxLength", MaxLength.ToString());
            }

            base.OnPreRender(e);
        }