示例#1
0
        /// <summary>
        /// 创建子控件
        /// </summary>
        protected override void CreateChildControls()
        {
            if(ReadOnly)    //设置日期控件只读
            {
                DateTextBox.Attributes.Add("readonly", "readonly");
            }
            DateTextBox.Size = 8;
            DateTextBox.ID = this.ID;
            this.Controls.Add(DateTextBox);

            ImgHtmlImage.Src = ImageUrl;
            ImgHtmlImage.Align = "bottom";
            ImgHtmlImage.Attributes.Add("onclick", "showcalendar(event, $('" + this.ID + "_" + this.ID + "'))");
            ImgHtmlImage.Attributes.Add("class", "calendarimg");
            this.Controls.Add(ImgHtmlImage);

            System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1 = new RegularExpressionValidator();
            RegularExpressionValidator1.ID = RegularExpressionValidator1.ClientID;
            RegularExpressionValidator1.Display = System.Web.UI.WebControls.ValidatorDisplay.Dynamic;
            RegularExpressionValidator1.ControlToValidate = DateTextBox.ID;
            RegularExpressionValidator1.ValidationExpression = @"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-9]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$";
            RegularExpressionValidator1.ErrorMessage = "请输入正确的日期,如:2006-1-1";
            this.Controls.Add(RegularExpressionValidator1);

            base.CreateChildControls();
        }
示例#2
0
        //Fill page with dynamic controls showing products in database
        private void GenerateShopControls()
        {
            ArrayList coffeeList = ConnectionClass.GetCoffeeByType("%");

            foreach (Coffee coffee in coffeeList)
            {
                //Create Controls
                Panel coffeePanel = new Panel();
                Image image = new Image { ImageUrl = coffee.Image, CssClass = "ProductsImage" };
                Literal literal = new Literal { Text = "<br />" };
                Literal literal2 = new Literal { Text = "<br />" };
                Label lblName = new Label { Text = coffee.Name, CssClass = "ProductsName" };
                Label lblPrice = new Label { Text = String.Format("{0:0.00}",coffee.Price) + "<br />", CssClass = "ProductsPrice" };
                TextBox textBox = new TextBox {ID = coffee.Id.ToString(), CssClass = "ProductsTextBox", Text = "0", Width = 60};

                //Add validation so only numbers can be entered into the textfields
                var validator = new RegularExpressionValidator
                                    {
                                        ValidationExpression = "^[0-9]*",
                                        ControlToValidate = textBox.ID,
                                        ErrorMessage = "Please enter a number."
                                    };

                //Add controls to Panels
                coffeePanel.Controls.Add(image);
                coffeePanel.Controls.Add(literal);
                coffeePanel.Controls.Add(lblName);
                coffeePanel.Controls.Add(literal2);
                coffeePanel.Controls.Add(lblPrice);
                coffeePanel.Controls.Add(textBox);
                coffeePanel.Controls.Add(validator);

                pnlProducts.Controls.Add(coffeePanel);
            }
        }
示例#3
0
        protected override void CreateChildControls()
        {
            ctrl    = new System.Web.UI.WebControls.TextBox();
            ctrl.ID = "ctrl";
            Controls.Add(ctrl);

            ctrlRegularExpressionValidator    = new System.Web.UI.WebControls.RegularExpressionValidator();
            ctrlRegularExpressionValidator.ID = "ctrlRegularExpressionValidator";
            Controls.Add(ctrl);
        }
 public static void CreateValidatorForMultiLineTextBox(DynamicColumnInstanceDto instance, Control editControlsPanel, string validationGroup)
 {
     RegularExpressionValidator validator = new RegularExpressionValidator();
     validator.ID = "RegularExpressionValidator" + Constants.DynamicColumnControlPrefix + instance.Id;
     validator.ValidationGroup = validationGroup;
     validator.ValidationExpression = "^(.|\n){0," + instance.DataSize.Value.ToString(CultureInfo.InvariantCulture) + "}$";
     validator.ErrorMessage = instance.FormLabel + " must be " + instance.DataSize.Value.ToString(CultureInfo.InvariantCulture) + " characters or less.";
     validator.Display = ValidatorDisplay.Dynamic;
     validator.ControlToValidate = Constants.DynamicColumnControlPrefix + instance.Name;
     validator.Text = _validationTextImage;
     editControlsPanel.Controls.Add(validator);
 }
示例#5
0
文件: Field.cs 项目: radtek/Webmin
        public override List <WC.BaseValidator> GetValidators()
        {
            List <WC.BaseValidator> res = base.GetValidators();

            WC.RegularExpressionValidator numVal = new WC.RegularExpressionValidator();
            numVal.ErrorMessage         = "The field " + Caption + " must be an integer";
            numVal.ControlToValidate    = myControl.ID;
            numVal.ValidationExpression = "[0-9]+";
            numVal.Display = WC.ValidatorDisplay.None;
            res.Add(numVal);
            return(res);
        }
示例#6
0
 private static RegularExpressionValidator GetImageValidator(Control controlToValidate)
 {
     RegularExpressionValidator validator = new RegularExpressionValidator();
     validator.ID = controlToValidate.ID + "RegexValidator";
     validator.ErrorMessage = "<br/>" + Resources.ScrudResource.InvalidImage;
     validator.CssClass = "form-error";
     validator.ControlToValidate = controlToValidate.ID;
     validator.EnableClientScript = true;
     validator.SetFocusOnError = true;
     validator.Display = ValidatorDisplay.Dynamic;
     validator.ValidationExpression = @"(.*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[bB][mM][pP])$)";
     return validator;
 }
示例#7
0
 protected override void CreateChildControls()
 {
     base.CreateChildControls();
     if (!string.IsNullOrEmpty(Label)) {
         if (Parent != null && Parent.Controls.Contains(this)) {
             var label = new Label();
             label.AssociatedControlID = UniqueID;
             label.Text = Label;
             PlaceLabel(label);
         }
     }
     if (!string.IsNullOrEmpty(Valid) && !string.IsNullOrEmpty(InvalidMessage)) {
         var val = new RegularExpressionValidator();
         val.ID = UniqueID + "_RegularExpressionValidator";
         val.ValidationExpression = Valid;
         val.Text = InvalidMessage;
         val.ControlToValidate = UniqueID;
         var callout = new AjaxControlToolkit.ValidatorCalloutExtender();
         callout.ID = UniqueID + "_RegularExpressionValidatorCalloutExtender";
         callout.TargetControlID = val.ID;
         Controls.Add(val);
         Controls.Add(callout);
     }
     if (!string.IsNullOrEmpty(ConfirmationOf) && !string.IsNullOrEmpty(MismatchMessage)) {
         var val = new CompareValidator();
         val.ID = UniqueID + "_CompareValidator";
         val.ControlToCompare = ConfirmationOf;
         val.Text = MismatchMessage;
         val.ControlToValidate = UniqueID;
         var callout = new AjaxControlToolkit.ValidatorCalloutExtender();
         callout.ID = UniqueID + "_CompareValidatorCalloutExtender";
         callout.TargetControlID = val.ID;
         Controls.Add(val);
         Controls.Add(callout);
     }
     if (Required) {
         var val = new RequiredFieldValidator();
         val.ID = UniqueID + "_RequiredFieldValidator";
         val.Text = MissingMessage;
         val.ControlToValidate = UniqueID;
         var callout = new AjaxControlToolkit.ValidatorCalloutExtender();
         callout.ID = UniqueID + "_RequiredFieldValidatorCalloutExtender";
         callout.TargetControlID = val.ID;
         Controls.Add(val);
         Controls.Add(callout);
     }
     if (!string.IsNullOrEmpty(Placeholder)) {
         Attributes["placeholder"] = "Placeholder";
     }
 }
示例#8
0
 private static RegularExpressionValidator GetImageValidator(Control controlToValidate, string cssClass)
 {
     using (RegularExpressionValidator validator = new RegularExpressionValidator())
     {
         validator.ID = controlToValidate.ID + "RegexValidator";
         validator.ErrorMessage = @"<br/>" + Titles.InvalidImage;
         validator.CssClass = cssClass;
         validator.ControlToValidate = controlToValidate.ID;
         validator.EnableClientScript = true;
         validator.SetFocusOnError = true;
         validator.Display = ValidatorDisplay.Dynamic;
         validator.ValidationExpression = @"(.*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[bB][mM][pP])$)";
         return validator;
     }
 }
        private void BindControls()
        {
            imageFieldPicture = TemplateContainer.FindControl("imageFieldPicture") as FileUpload;
            ddlExistingPicture = TemplateContainer.FindControl("ddlExistingPicture") as DropDownList;
            imgExistingPicture = TemplateContainer.FindControl("imgExistingPicture") as Image;

            lbExistingPicture = TemplateContainer.FindControl("lbExistingPicture") as Label;
            lbExistingPicture.Text = SPUtility.GetLocalizedString("$Resources:SelectExistingPicture", "ImageField", (uint)SPContext.Current.Web.Locale.LCID);

            lbOrNewPicture = TemplateContainer.FindControl("lbOrNewPicture") as Label;
            lbOrNewPicture.Text = SPUtility.GetLocalizedString("$Resources:UploadNewPicture", "ImageField", (uint)SPContext.Current.Web.Locale.LCID);

            revUploadPicture = TemplateContainer.FindControl("revUploadPicture") as RegularExpressionValidator;
            revUploadPicture.ErrorMessage = SPUtility.GetLocalizedString("$Resources:InvalidPicture", "ImageField", (uint)SPContext.Current.Web.Locale.LCID);
        }
示例#10
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            _requiredFieldValidator = new RequiredFieldValidator
                                          {
                                              ID = string.Format("{0}_rfv", base.ID),
                                              ControlToValidate = base.ID,
                                              Enabled = Required,
                                              Visible = Required,
                                              ErrorMessage = string.Format("{0} must not be empty.", Title),
                                              Display = ValidatorDisplay.Dynamic,
                                              ValidationGroup = base.ValidationGroup
                                          };

            _requiredFieldValidator.Controls.Add(new Literal {Text = "&nbsp;"});
            //Add error image
            _requiredFieldValidator.Controls.Add(ValidationImageHelper.GetImage(_requiredFieldValidator,
                                                                                _requiredFieldValidator.ErrorMessage));

            //Add required field validator to control
            base.Controls.Add(_requiredFieldValidator);

            _regularExpressionValidator = new RegularExpressionValidator
                                              {
                                                  ID = string.Format("{0}_rev", base.ID),
                                                  ControlToValidate = base.ID,
                                                  Enabled = ValidType != ValidationType.None,
                                                  Visible = ValidType != ValidationType.None,
                                                  ErrorMessage = ValidationHelper.GetValidationErrorMessage(ValidType),
                                                  ValidationExpression =
                                                      ValidationHelper.GetValidationExpression(ValidType),
                                                  Display = ValidatorDisplay.Dynamic,
                                                  ValidationGroup = base.ValidationGroup
                                              };

            _regularExpressionValidator.Controls.Add(new Literal {Text = "&nbsp;"});
            //Add error image
            _regularExpressionValidator.Controls.Add(ValidationImageHelper.GetImage(_regularExpressionValidator,
                                                                                    _regularExpressionValidator.
                                                                                        ErrorMessage));

            //Add required field validator to control
            base.Controls.Add(_regularExpressionValidator);
        }
示例#11
0
        internal override void PopulateSpecification(FieldSpecification spec, bool isPostBack)
        {
            var textBox = new TextBox();
            textBox.ID = "ui" + Id;
            textBox.MaxLength = 150;
            textBox.CssClass = spec.SpanClass;

            spec.AddControl(GetLabel(textBox));
            spec.AddControl(textBox);
            if (Mandatory)
                spec.AddValidator(GetRequiredFieldValidator(textBox));

            var regularExpressionValidator = new RegularExpressionValidator();
            regularExpressionValidator.ValidationExpression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
            regularExpressionValidator.ControlToValidate = textBox.ID;
            regularExpressionValidator.ErrorMessage = InvalidEmailErrorMessage;
            spec.AddValidator(regularExpressionValidator);
            spec.Get = () => textBox.Text;
        }
        protected void AddValidationControls()
        {
            RequiredFieldValidator valdReqFirstName = new RequiredFieldValidator();
            TextBox txtFirstName = (TextBox)gvEligibility.HeaderRow.FindControl("txtFirstName");
            valdReqFirstName.ControlToValidate = txtFirstName.ID;
            valdReqFirstName.ErrorMessage = "<br/>Please Enter First Name.";
            valdReqFirstName.ValidationGroup = "Add";
            valdReqFirstName.ForeColor = System.Drawing.Color.Red;
            valdReqFirstName.Display = ValidatorDisplay.Dynamic;
            gvEligibility.HeaderRow.Cells[0].Controls.Add(valdReqFirstName);

            RequiredFieldValidator valdReqLastName = new RequiredFieldValidator();
            TextBox txtLastName = (TextBox)gvEligibility.HeaderRow.FindControl("txtLastName");
            valdReqLastName.ControlToValidate = txtLastName.ID;
            valdReqLastName.ErrorMessage = "<br/>Please Enter Last Name.";
            valdReqLastName.ForeColor = System.Drawing.Color.Red;
            valdReqLastName.ValidationGroup = "Add";
            valdReqLastName.Display = ValidatorDisplay.Dynamic;
            gvEligibility.HeaderRow.Cells[1].Controls.Add(valdReqLastName);

            RequiredFieldValidator valdReqSSN = new RequiredFieldValidator();
            TextBox txtSSN = (TextBox)gvEligibility.HeaderRow.FindControl("txtSSN");
            RegularExpressionValidator valregexSSN = new RegularExpressionValidator();
            valregexSSN.ControlToValidate = txtSSN.ID;
            valregexSSN.ValidationExpression = "\\d{4}";
            valregexSSN.ForeColor = System.Drawing.Color.Red;
            valregexSSN.ErrorMessage = "Please Enter Last Four Digits Only.";
            valregexSSN.SetFocusOnError = true;
            valregexSSN.ValidationGroup = "Add";
            valregexSSN.Display = ValidatorDisplay.Dynamic;
            gvEligibility.HeaderRow.Cells[2].Controls.Add(valregexSSN);
            //txtSSN.
            valdReqSSN.ControlToValidate = txtSSN.ID;
            valdReqSSN.SetFocusOnError = true;
            valdReqSSN.ForeColor = System.Drawing.Color.Red;
            valdReqSSN.ErrorMessage = "<br/>Please Enter SSN.";
            valdReqSSN.ValidationGroup = "Add";
            valdReqSSN.Display = ValidatorDisplay.Dynamic;
            gvEligibility.HeaderRow.Cells[2].Controls.Add(valdReqSSN);
        }
 /// <summary>
 /// Init routine
 /// </summary>
 protected virtual void InitializeRegularExpressionValidator(ref RegularExpressionValidator rev,
     string controlId,
     string controlToValidate,
     string validationExpression,
     string validationGroup,
     string text,
     string errMessage,
     bool enableClientScript,
     ValidatorDisplay validatorDisplay)
 {
     if (rev == null)
     {
         rev = new RegularExpressionValidator();
         rev.ID = controlId;
         rev.ControlToValidate = controlToValidate;
         rev.ValidationExpression = validationExpression;
         rev.ValidationGroup = validationGroup;
         rev.Text = text;
         rev.ErrorMessage = errMessage;
         rev.EnableClientScript = enableClientScript;
     }
 }
        private void GenerateControls()
        {
            List<Drinks> drinkList = drinksGateway.GetAllDrinks();

            foreach (Drinks aDrinks in drinkList) {
                Panel drinksPanal = new Panel();
                Image image = new Image { ImageUrl = aDrinks.Image, CssClass = "ProductsImage" };
                Literal litaral = new Literal() { Text = "<br/>" };
                Literal literal2 = new Literal() { Text = "<br/>" };
                Label nameLabel = new Label { Text = aDrinks.Name, CssClass = "ProductsName" };
                Label priceLabel=new Label{Text=String.Format("{0:0.00}",aDrinks.Price+" tk <br/>"), CssClass="ProductsPrice"};
                TextBox textBox = new TextBox { ID = ""+aDrinks.Id+"", CssClass = "ProductTextBox", Width = 60, Text = "0" };
                RegularExpressionValidator reexv = new RegularExpressionValidator { ValidationExpression = "^[0-9]*", ControlToValidate = textBox.ID, ErrorMessage = "Please enter a number!" };
                drinksPanal.Controls.Add(image);
                drinksPanal.Controls.Add(litaral);
                drinksPanal.Controls.Add(nameLabel);
                drinksPanal.Controls.Add(literal2);
                drinksPanal.Controls.Add(priceLabel);
                drinksPanal.Controls.Add(textBox);
                drinksPanal.Controls.Add(reexv);

                productPanel.Controls.Add(drinksPanal);
            }
        }
 protected override WebCntrls.BaseValidator CreateWebValidator()
 {
     _webRegularExpressionValidator = new WebCntrls.RegularExpressionValidator();
     return(_webRegularExpressionValidator);
 }
        /// <summary>
        /// Init the components of the panel through the special pageid
        /// </summary>
        private void InitComponents()
        {
            HtmlTable T_Content = new HtmlTable();
            T_Content.CellPadding = 0;
            T_Content.CellSpacing = 0;
            T_Content.Width = "100%";
            T_Content.Border = 0;
            T_Content.ID = "T_Content_" + ID;
            this.Controls.Add(T_Content);

            UD_DetailViewBLL _DetailViewBll = new UD_DetailViewBLL(DetailViewCode, true);

            IList<UD_Panel> _panellist = _DetailViewBll.GetDetailPanels();
            Hashtable _htFieldControlsInfo = new Hashtable();

            foreach (UD_Panel _panelmodel in _panellist)
            {
                HtmlTableRow tr_panel = new HtmlTableRow();//Create one TableRow for a panel
                tr_panel.ID = _panelmodel.Code;
                if (_panelmodel.Enable.ToUpper() == "N")
                    tr_panel.Visible = false;
                HtmlTableCell tc_panel = new HtmlTableCell();
                string _tablestytle = _panelmodel.TableStyle;
                string[] _tablestyles = _panelmodel.TableStyle.Split(new char[] { ',' });

                if (_tablestyles.Length < 3)
                    _tablestyles = ("tabForm,dataLabel,dataField").Split(new char[] { ',' });

                #region The title of the panel
                if (_panelmodel.Name != "")
                {
                    HtmlTable tb_panel_title = new HtmlTable();
                    tb_panel_title.CellPadding = 0;
                    tb_panel_title.CellSpacing = 0;
                    tb_panel_title.Width = "100%";
                    tb_panel_title.Height = "28px";
                    tb_panel_title.Border = 0;
                    tb_panel_title.Attributes["class"] = "h3Row";
                    HtmlTableRow tr_panel_title = new HtmlTableRow();
                    HtmlTableCell tc_panel_title = new HtmlTableCell();
                    tc_panel_title.InnerHtml = "<h3>" + _panelmodel.Name + "</h3>";
                    tr_panel_title.Cells.Add(tc_panel_title);
                    tb_panel_title.Rows.Add(tr_panel_title);
                    tc_panel.Controls.Add(tb_panel_title);
                }
                #endregion

                #region The content of the panel
                IList<UD_Panel_ModelFields> fields = new UD_PanelBLL(_panelmodel.ID, true).GetModelFields();

                int FieldCount = _panelmodel.FieldCount;

                HtmlTable tb_panel_content = new HtmlTable();
                tb_panel_content.Width = "100%";
                tb_panel_content.Attributes["class"] = _tablestyles[0];
                int i = 0;
                foreach (UD_Panel_ModelFields _panel_modelfields in fields)
                {
                    if (_panel_modelfields.Visible == "N") continue;

                    UD_ModelFields _modelfieldsmodel = new UD_ModelFieldsBLL(_panel_modelfields.FieldID, true).Model;
                    UD_TableList _tablemodel = new UD_TableListBLL(_modelfieldsmodel.TableID, true).Model;

                    #region 判断该控件是否已存在
                    if (_htFieldControlsInfo.Contains(_tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName)) continue;
                    #endregion

                    #region 判断是否要增加新行
                    HtmlTableRow tr_panel_detail;
                    if (i >= FieldCount || i == 0)
                    {
                        tr_panel_detail = new HtmlTableRow();
                        tb_panel_content.Rows.Add(tr_panel_detail);
                        i = 0;
                    }
                    else
                    {
                        tr_panel_detail = tb_panel_content.Rows[tb_panel_content.Rows.Count - 1];
                    }
                    #endregion

                    #region 增加Label Cell
                    HtmlTableCell tc_displayname = new HtmlTableCell();
                    tc_displayname.Attributes["Class"] = _tablestyles[1];
                    tc_displayname.InnerText = string.IsNullOrEmpty(_panel_modelfields.LabelText) ?
                        _modelfieldsmodel.DisplayName : _panel_modelfields.LabelText;
                    if (tc_displayname.InnerText.Length <= 6)
                        tc_displayname.Attributes["Style"] = "width: 80px; height: 18px;";
                    else
                        tc_displayname.Attributes["Style"] = "width: 100px; height: 18px;";
                    tc_displayname.Attributes["nowrap"] = "nowrap";
                    tr_panel_detail.Cells.Add(tc_displayname);
                    #endregion

                    #region 增加Field Cell
                    HtmlTableCell tc_control = new HtmlTableCell();
                    tc_control.Attributes["Class"] = _tablestyles[2];
                    if (_panel_modelfields.ColSpan > 0)
                    {
                        if (i + _panel_modelfields.ColSpan <= FieldCount)
                        {
                            tc_control.ColSpan = 2 * _panel_modelfields.ColSpan - 1;
                            i = i + _panel_modelfields.ColSpan;
                        }
                        else
                        {
                            tc_control.ColSpan = 2 * (FieldCount - i) - 1;
                            i = 0;
                        }

                    }
                    else
                    {
                        i++;
                    }

                    WebControl control = null;

                    int RelationType = _modelfieldsmodel.RelationType;
                    string RelationTableName = _modelfieldsmodel.RelationTableName;
                    string RelationValueField = _modelfieldsmodel.RelationValueField;
                    string RelationTextField = _modelfieldsmodel.RelationTextField;

                    #region 根据控件类型生成相应的控件
                    switch (_panel_modelfields.ControlType)
                    {
                        case 1://Label
                            control = new Label();
                            break;
                        case 2://TextBox
                            control = new TextBox();
                            if (_modelfieldsmodel.DataType == 4)
                            {
                                control.Attributes["onfocus"] = "WdatePicker();";
                            }
                            break;
                        case 3://DropDownList
                            control = new DropDownList();
                            if (RelationType == 1)//Relation to the dictionary
                            {
                                ((DropDownList)control).DataSource = DictionaryBLL.GetDicCollections(RelationTableName, true);
                            }
                            else if (RelationType == 2)//Relation to the model table
                            {
                                ((DropDownList)control).DataSource = TreeTableBLL.GetRelationTableSourceData(RelationTableName, RelationValueField, RelationTextField);
                            }
                            else
                                break;

                            ((DropDownList)control).DataTextField = "Value";
                            ((DropDownList)control).DataValueField = "Key";
                            ((DropDownList)control).DataBind();
                            if (_modelfieldsmodel.DataType != 5)
                                ((DropDownList)control).Items.Insert(0, new ListItem("请选择...", "0"));
                            else
                                ((DropDownList)control).Items.Insert(0, new ListItem("请选择...", Guid.Empty.ToString()));
                            break;
                        case 4://RadioButtonList
                            control = new RadioButtonList();
                            if (RelationType == 1)//Relation to the dictionary
                            {
                                ((RadioButtonList)control).DataSource = DictionaryBLL.GetDicCollections(RelationTableName, true);
                            }
                            else if (RelationType == 2)//Relation to the model table
                            {
                                ((RadioButtonList)control).DataSource = TreeTableBLL.GetRelationTableSourceData(RelationTableName, RelationValueField, RelationTextField);
                            }
                            else
                                break;

                            ((RadioButtonList)control).RepeatColumns = 6;
                            ((RadioButtonList)control).RepeatDirection = RepeatDirection.Horizontal;
                            ((RadioButtonList)control).DataTextField = "Value";
                            ((RadioButtonList)control).DataValueField = "Key";
                            ((RadioButtonList)control).DataBind();
                            if (((RadioButtonList)control).Items.Count != 0) ((RadioButtonList)control).SelectedIndex = 0;
                            break;
                        case 5://MutiLinesTextBox
                            control = new TextBox();
                            ((TextBox)control).TextMode = TextBoxMode.MultiLine;
                            if (_panel_modelfields.ControlHeight > 0) ((TextBox)control).Height = new Unit(_panel_modelfields.ControlHeight);
                            break;
                        case 6://TextBox supports search
                            control = new MCSSelectControl();
                            if (RelationType == 2)//Relation to the model table
                            {
                                control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName;

                                if (_panel_modelfields.SearchPageURL != "")
                                    ((MCSSelectControl)control).PageUrl = _panel_modelfields.SearchPageURL;
                                else if (_modelfieldsmodel.SearchPageURL != "")
                                    ((MCSSelectControl)control).PageUrl = _modelfieldsmodel.SearchPageURL;
                            }
                            break;
                        case 7://MCSTreeControl

                            control = new MCSTreeControl();

                            if (RelationType == 2)//Relation to the model table
                            {
                                control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName;

                                if (_modelfieldsmodel.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                                {
                                    #region 如果为管理片区字段,则取所能管辖的片区
                                    if (System.Web.HttpContext.Current.Session["AccountType"] == null ||
                                    (int)System.Web.HttpContext.Current.Session["AccountType"] == 1)
                                    {
                                        //员工
                                        Org_StaffBLL staff = new Org_StaffBLL((int)System.Web.HttpContext.Current.Session["UserID"]);
                                        ((MCSTreeControl)control).DataSource = staff.GetStaffOrganizeCity();
                                        ((MCSTreeControl)control).IDColumnName = "ID";
                                        ((MCSTreeControl)control).NameColumnName = "Name";
                                        ((MCSTreeControl)control).ParentColumnName = "SuperID";

                                        if (((MCSTreeControl)control).DataSource.Select("ID = 1").Length > 0 || staff.Model.OrganizeCity == 0)
                                        {
                                            ((MCSTreeControl)control).RootValue = "0";
                                            if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = "0";
                                        }
                                        else
                                        {
                                            ((MCSTreeControl)control).RootValue = new Addr_OrganizeCityBLL(staff.Model.OrganizeCity).Model.SuperID.ToString();
                                            if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = staff.Model.OrganizeCity.ToString();
                                        }
                                    }
                                    else if ((int)System.Web.HttpContext.Current.Session["AccountType"] == 2 &&
                                     System.Web.HttpContext.Current.Session["OrganizeCity"] != null)
                                    {
                                        //商业客户

                                        int city = (int)System.Web.HttpContext.Current.Session["OrganizeCity"];
                                        Addr_OrganizeCityBLL citybll = new Addr_OrganizeCityBLL(city);
                                        ((MCSTreeControl)control).DataSource = citybll.GetAllChildNodeIncludeSelf();
                                        ((MCSTreeControl)control).RootValue = citybll.Model.SuperID.ToString();
                                        ((MCSTreeControl)control).IDColumnName = "ID";
                                        ((MCSTreeControl)control).NameColumnName = "Name";
                                        ((MCSTreeControl)control).ParentColumnName = "SuperID";

                                        if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = city.ToString();
                                    }
                                    #endregion
                                }
                                else if (_modelfieldsmodel.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                                {
                                    ((MCSTreeControl)control).TableName = "MCS_SYS.dbo.Addr_OfficialCity";
                                    ((MCSTreeControl)control).IDColumnName = "ID";
                                    ((MCSTreeControl)control).NameColumnName = "Name";
                                    ((MCSTreeControl)control).ParentColumnName = "SuperID";
                                    ((MCSTreeControl)control).RootValue = "0";
                                    if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = "0";
                                }
                                else
                                {
                                    ((MCSTreeControl)control).TableName = RelationTableName;
                                    ((MCSTreeControl)control).IDColumnName = RelationValueField;
                                    ((MCSTreeControl)control).NameColumnName = RelationTextField;
                                    ((MCSTreeControl)control).ParentColumnName = "SuperID";
                                }
                            }
                            break;
                    }
                    #endregion

                    control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName;
                    control.Enabled = _panel_modelfields.Enable.ToUpper() == "Y";

                    if (_panel_modelfields.ControlWidth > 0) control.Width = _panel_modelfields.ControlWidth;

                    tc_control.Controls.Add(control);

                    #region 如果是文本框时,加上输入验证控件
                    if (_panel_modelfields.IsRequireField == "Y")
                    {
                        Label lbl_reqinfo = new Label();
                        lbl_reqinfo.Text = "&nbsp;&nbsp;*";
                        lbl_reqinfo.ForeColor = System.Drawing.Color.Red;
                        tc_control.Controls.Add(lbl_reqinfo);
                    }

                    if (_panel_modelfields.ControlType == 2 || _panel_modelfields.ControlType == 5)
                    {
                        if (_panel_modelfields.IsRequireField == "Y")
                        {
                            RequiredFieldValidator _requiredfieldvalidator = new RequiredFieldValidator();
                            _requiredfieldvalidator.ControlToValidate = control.ID;
                            _requiredfieldvalidator.Display = ValidatorDisplay.Dynamic;
                            _requiredfieldvalidator.ErrorMessage = "必填";
                            _requiredfieldvalidator.ForeColor = System.Drawing.Color.Red;
                            _requiredfieldvalidator.ValidationGroup = _validationgroup;

                            tc_control.Controls.Add(_requiredfieldvalidator);
                        }

                        if (_panel_modelfields.RegularExpression != "")
                        {
                            RegularExpressionValidator _regularexpressionvalidator = new RegularExpressionValidator();
                            _regularexpressionvalidator.ControlToValidate = control.ID;
                            _regularexpressionvalidator.ErrorMessage = "数据格式不正确";
                            _regularexpressionvalidator.ForeColor = System.Drawing.Color.Red;
                            _regularexpressionvalidator.ValidationExpression = _panel_modelfields.RegularExpression;
                            _regularexpressionvalidator.ValidationGroup = ValidationGroup;
                            _regularexpressionvalidator.Display = ValidatorDisplay.Dynamic;
                            tc_control.Controls.Add(_regularexpressionvalidator);
                        }
                        else
                        {
                            if (_modelfieldsmodel.DataType == 1 || _modelfieldsmodel.DataType == 2 || _modelfieldsmodel.DataType == 4)        //非varchar 字符串
                            {
                                CompareValidator _comparevalidator = new CompareValidator();
                                _comparevalidator.ControlToValidate = control.ID;
                                _comparevalidator.Operator = ValidationCompareOperator.DataTypeCheck;
                                _comparevalidator.Display = ValidatorDisplay.Dynamic;
                                _comparevalidator.ForeColor = System.Drawing.Color.Red;
                                _comparevalidator.ValidationGroup = _validationgroup;

                                if (_modelfieldsmodel.DataType == 1)//int
                                {
                                    _comparevalidator.Type = ValidationDataType.Integer;
                                    _comparevalidator.ErrorMessage = "应为整数";

                                }
                                if (_modelfieldsmodel.DataType == 2)//decimal
                                {
                                    _comparevalidator.Type = ValidationDataType.Double;
                                    _comparevalidator.ErrorMessage = "应为数字";
                                }
                                if (_modelfieldsmodel.DataType == 4)//datetime
                                {
                                    _comparevalidator.Type = ValidationDataType.Date;
                                    _comparevalidator.ErrorMessage = "日期格式不正确";
                                }
                                tc_control.Controls.Add(_comparevalidator);
                            }
                        }
                    }
                    #endregion

                    if (!string.IsNullOrEmpty(_panel_modelfields.Description))
                    {
                        Label lb = new Label();
                        lb.Text = "  " + _panel_modelfields.Description;
                        tc_control.Controls.Add(lb);
                    }

                    tr_panel_detail.Cells.Add(tc_control);
                    #endregion

                    #region 将控件记录到字段控件HashTable中
                    FieldControlInfo fieldcontrolinfo = new FieldControlInfo();

                    fieldcontrolinfo.FieldID = _modelfieldsmodel.ID;
                    fieldcontrolinfo.FieldName = _modelfieldsmodel.FieldName;
                    fieldcontrolinfo.ModelName = _tablemodel.ModelClassName;
                    fieldcontrolinfo.ControlType = _panel_modelfields.ControlType;
                    fieldcontrolinfo.ControlName = control.ID;
                    fieldcontrolinfo.DisplayMode = _panel_modelfields.DisplayMode;
                    fieldcontrolinfo.Panel_Field_ID = _panel_modelfields.ID;
                    _htFieldControlsInfo.Add(fieldcontrolinfo.ControlName, fieldcontrolinfo);
                    #endregion
                }
                #endregion

                tc_panel.Controls.Add(tb_panel_content);
                tr_panel.Cells.Add(tc_panel);
                T_Content.Rows.Add(tr_panel);
            }
            ViewState["FieldControlsInfo"] = _htFieldControlsInfo;
        }
示例#17
0
        protected override void InitializeControls()
        {
            base.InitializeControls();

            panel = new Panel();

            Table table = new Table();
            TableRow row1, row2, row3;
            TableCell cell;

            row1 = new TableRow();
            row3 = new TableRow();
            if (showExample)
            {
                table.Rows.Add(row1);
            }

            table.Rows.Add(row2 = new TableRow());

            if (showExample)
            {
                table.Rows.Add(row3);
            }

            // top row
            cell = new TableCell();
            cell.Style[HtmlTextWriterStyle.Color] = "gray";
            cell.Style[HtmlTextWriterStyle.FontSize] = "smaller";
            requiredValidator = new RequiredFieldValidator();
            requiredValidator.ErrorMessage = RequiredTextDefault + RequiredTextSuffix;
            requiredValidator.Text = RequiredTextDefault + RequiredTextSuffix;
            requiredValidator.Display = ValidatorDisplay.Dynamic;
            requiredValidator.ControlToValidate = WrappedTextBox.ID;
            requiredValidator.ValidationGroup = ValidationGroupDefault;

            uriFormatValidator = new RegularExpressionValidator();
            uriFormatValidator.ErrorMessage = UriFormatTextDefault + RequiredTextSuffix;
            uriFormatValidator.Text = UriFormatTextDefault + RequiredTextSuffix;
            uriFormatValidator.ValidationExpression = UriRegex;
            uriFormatValidator.Display = ValidatorDisplay.Dynamic;
            uriFormatValidator.ControlToValidate = WrappedTextBox.ID;
            uriFormatValidator.ValidationGroup = ValidationGroupDefault;
            if (uriValidatorEnabled)
            {
                requiredValidator.Enabled = true;
                uriFormatValidator.Enabled = true;
                cell.Controls.Add(requiredValidator);
                cell.Controls.Add(uriFormatValidator);
            }
            else
            {
                requiredValidator.Enabled = false;
                uriFormatValidator.Enabled = false;
            }
            examplePrefixLabel = new Label();
            examplePrefixLabel.Text = ExamplePrefixDefault;
            cell.Controls.Add(examplePrefixLabel);
            cell.Controls.Add(new LiteralControl(" "));
            exampleUrlLabel = new Label();
            exampleUrlLabel.Font.Bold = true;
            exampleUrlLabel.Text = ExampleUrlDefault;
            cell.Controls.Add(exampleUrlLabel);
            row1.Cells.Add(cell);

            //  row2
            buttonCell = new TableCell();
            buttonCell.Controls.Add(WrappedTextBox);
            row2.Cells.Add(buttonCell);

            // row3
            cell = new TableCell();
            loginButton = new Button();
            loginButton.ID = "loginButton";
            loginButton.Text = ButtonTextDefault;
            loginButton.ToolTip = ButtonToolTipDefault;
            loginButton.Click += new EventHandler(loginButton_Click);
            loginButton.ValidationGroup = ValidationGroupDefault;
            #if !Mono
            panel.DefaultButton = loginButton.ID;
            #endif
            cell.Controls.Add(loginButton);
            if (showExample)
            {
                row3.Cells.Add(cell);
            }
            else
            {
                row2.Cells.Add(cell);
            }

            panel.Controls.Add(table);
        }
 private void ConstructControls(CreateUserWizard.CreateUserStepContainer container)
 {
     string validationGroup = this._wizard.ValidationGroup;
     container.Title = CreateUserWizard.CreateLiteral();
     container.InstructionLabel = CreateUserWizard.CreateLiteral();
     container.PasswordHintLabel = CreateUserWizard.CreateLiteral();
     TextBox box = new TextBox {
         ID = "UserName"
     };
     container.UserNameTextBox = box;
     TextBox box2 = new TextBox {
         ID = "Password",
         TextMode = TextBoxMode.Password
     };
     container.PasswordTextBox = box2;
     TextBox box3 = new TextBox {
         ID = "ConfirmPassword",
         TextMode = TextBoxMode.Password
     };
     container.ConfirmPasswordTextBox = box3;
     bool enableValidation = true;
     container.UserNameRequired = CreateUserWizard.CreateRequiredFieldValidator("UserNameRequired", validationGroup, container.UserNameTextBox, enableValidation);
     container.UserNameLabel = CreateUserWizard.CreateLabelLiteral(container.UserNameTextBox);
     container.PasswordLabel = CreateUserWizard.CreateLabelLiteral(container.PasswordTextBox);
     container.ConfirmPasswordLabel = CreateUserWizard.CreateLabelLiteral(container.ConfirmPasswordTextBox);
     Image image = new Image();
     image.PreventAutoID();
     container.HelpPageIcon = image;
     HyperLink link = new HyperLink {
         ID = "HelpLink"
     };
     container.HelpPageLink = link;
     Literal literal = new Literal {
         ID = "ErrorMessage"
     };
     container.ErrorMessageLabel = literal;
     TextBox box4 = new TextBox {
         ID = "Email"
     };
     container.EmailTextBox = box4;
     container.EmailRequired = CreateUserWizard.CreateRequiredFieldValidator("EmailRequired", validationGroup, container.EmailTextBox, enableValidation);
     container.EmailLabel = CreateUserWizard.CreateLabelLiteral(container.EmailTextBox);
     RegularExpressionValidator validator = new RegularExpressionValidator {
         ID = "EmailRegExp",
         ControlToValidate = "Email",
         ErrorMessage = this._wizard.EmailRegularExpressionErrorMessage,
         ValidationExpression = this._wizard.EmailRegularExpression,
         ValidationGroup = validationGroup,
         Display = ValidatorDisplay.Dynamic,
         Enabled = enableValidation,
         Visible = enableValidation
     };
     container.EmailRegExpValidator = validator;
     container.PasswordRequired = CreateUserWizard.CreateRequiredFieldValidator("PasswordRequired", validationGroup, container.PasswordTextBox, enableValidation);
     container.ConfirmPasswordRequired = CreateUserWizard.CreateRequiredFieldValidator("ConfirmPasswordRequired", validationGroup, container.ConfirmPasswordTextBox, enableValidation);
     RegularExpressionValidator validator2 = new RegularExpressionValidator {
         ID = "PasswordRegExp",
         ControlToValidate = "Password",
         ErrorMessage = this._wizard.PasswordRegularExpressionErrorMessage,
         ValidationExpression = this._wizard.PasswordRegularExpression,
         ValidationGroup = validationGroup,
         Display = ValidatorDisplay.Dynamic,
         Enabled = enableValidation,
         Visible = enableValidation
     };
     container.PasswordRegExpValidator = validator2;
     CompareValidator validator3 = new CompareValidator {
         ID = "PasswordCompare",
         ControlToValidate = "ConfirmPassword",
         ControlToCompare = "Password",
         Operator = ValidationCompareOperator.Equal,
         ErrorMessage = this._wizard.ConfirmPasswordCompareErrorMessage,
         ValidationGroup = validationGroup,
         Display = ValidatorDisplay.Dynamic,
         Enabled = enableValidation,
         Visible = enableValidation
     };
     container.PasswordCompareValidator = validator3;
     TextBox box5 = new TextBox {
         ID = "Question"
     };
     container.QuestionTextBox = box5;
     TextBox box6 = new TextBox {
         ID = "Answer"
     };
     container.AnswerTextBox = box6;
     container.QuestionRequired = CreateUserWizard.CreateRequiredFieldValidator("QuestionRequired", validationGroup, container.QuestionTextBox, enableValidation);
     container.AnswerRequired = CreateUserWizard.CreateRequiredFieldValidator("AnswerRequired", validationGroup, container.AnswerTextBox, enableValidation);
     container.QuestionLabel = CreateUserWizard.CreateLabelLiteral(container.QuestionTextBox);
     container.AnswerLabel = CreateUserWizard.CreateLabelLiteral(container.AnswerTextBox);
 }
        //Writes controls to page when editing
        protected override void CreateChildControls()
        {
            #region licensing
            SPWeb web = SPContext.Current.Web;
            WebRequest request = WebRequest.Create(web.Url + "/_layouts/SprocketValidator/key.xml");
            request.Credentials = CredentialCache.DefaultCredentials;
            WebResponse response = request.GetResponse();
            XmlTextReader reader = new XmlTextReader(response.GetResponseStream());
            reader.ReadToFollowing("key");
            reader.Read();

            string key = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(reader.Value));
            string[] values = key.Split(new char[] { '|' });
            DateTime expireDate = DateTime.ParseExact(values[values.Length - 1], "yyyyMMdd", CultureInfo.InvariantCulture);

            //HERE - does this need to change?
            if (!values.Contains<string>("*") && (DateTime.Now > expireDate || !values.Contains<string>(System.Environment.MachineName)))
            {
                base.CreateChildControls();
                tb_ValidatedInput = new TextBox();
                tb_ValidatedInput.ID = "tb_ValidatedInput";
                lbl_Instructions = new Label();
                lbl_Instructions.ID = "lbl_Instructions";
                lbl_Instructions.Text = "<b>The license for this product has expired or is invalid</b>";
                this.Controls.Add(lbl_Instructions);
                return;
            }
            #endregion

            base.CreateChildControls();
            tb_ValidatedInput = new TextBox();
            tb_ValidatedInput.ID = "tb_ValidatedInput";
            lbl_Instructions = new Label();
            lbl_Instructions.ID = "lbl_Instructions";
            lbl_Instructions.Text = "<br/><i>" + field.GetFieldAttribute("Instructions") + "</i>";

            this.Controls.Add(tb_ValidatedInput);

            int validationType;
            int.TryParse(field.GetFieldAttribute("ValidationType"), out validationType);
            switch ((ValidatedInput.ValidationTypes)validationType)
            {
                case ValidatedInput.ValidationTypes.Masked:
                    tb_ValidatedInput.Attributes.Add("onfocus", "$(this).mask('" + field.GetFieldAttribute("Mask") + "')");
                    break;
                case ValidatedInput.ValidationTypes.Regex:
                    regexVal = new RegularExpressionValidator();
                    regexVal.ValidationExpression = field.GetFieldAttribute("Regex") ?? string.Empty;
                    regexVal.ControlToValidate = "tb_ValidatedInput";
                    regexVal.Text = "Input invalid!";
                    this.Controls.Add(regexVal);
                    break;
                case ValidatedInput.ValidationTypes.Value:

                    rangeVal = new RangeValidator();
                    customVal = new CustomValidator();
                    compareVal = new CompareValidator();
                    typeCheckVal = new CompareValidator();

                    compareVal.ControlToValidate = "tb_ValidatedInput";
                    rangeVal.ControlToValidate = "tb_ValidatedInput";
                    customVal.ControlToValidate = "tb_ValidatedInput";
                    typeCheckVal.ControlToValidate = "tb_ValidatedInput";
                    typeCheckVal.Operator = ValidationCompareOperator.DataTypeCheck;

                    string value = field.GetFieldAttribute("ComparisonValue");
                    string errorMessage = "Your value must ";
                    string dataType = field.GetFieldAttribute("ComparisonDataType");

                    switch (dataType)
                    {
                        case "Number":
                            //rangeVal.Type = ValidationDataType.Double;
                            compareVal.Type = ValidationDataType.Double;
                            typeCheckVal.Type = ValidationDataType.Double;
                            typeCheckVal.ErrorMessage = "You must enter a number<br/>";
                            this.Controls.Add(typeCheckVal);
                            break;
                        case "Date":
                            //rangeVal.Type = ValidationDataType.Date;
                            compareVal.Type = ValidationDataType.Date;
                            typeCheckVal.Type = ValidationDataType.Date;
                            typeCheckVal.ErrorMessage = "You must enter a date<br/>";
                            this.Controls.Add(typeCheckVal);
                            break;
                        default:
                            //rangeVal.Type = ValidationDataType.String;
                            compareVal.Type = ValidationDataType.String;
                            //typeCheckVal.Type = ValidationDataType.String;
                            //typeCheckVal.ErrorMessage = "You must enter a word or words";
                            break;
                    }

                    switch (field.GetFieldAttribute("Comparison"))
                    {
                        case "Be Greater Than...":
                            errorMessage += "be greater than: " + value;
                            compareVal.ErrorMessage = errorMessage;
                            compareVal.Operator = ValidationCompareOperator.GreaterThan;
                            compareVal.ValueToCompare = value;
                            this.Controls.Add(compareVal);
                            break;
                        case "Be Less Than...":
                            errorMessage += "be less than: " + value;
                            compareVal.ErrorMessage = errorMessage;
                            compareVal.Operator = ValidationCompareOperator.LessThan;
                            compareVal.ValueToCompare = value;
                            this.Controls.Add(compareVal);
                            break;
                        case "Start With...":
                            errorMessage += "start with: " + value;
                            customVal.ErrorMessage = errorMessage;
                            customVal.ServerValidate += StartsWith;
                            this.Controls.Add(customVal);
                            break;
                        case "End With...":
                            errorMessage += "end with: " + value;
                            customVal.ErrorMessage = errorMessage;
                            customVal.ServerValidate += EndsWith;
                            this.Controls.Add(customVal);
                            break;
                        case "Contain...":
                        default:
                            errorMessage += "contain: " + value;
                            customVal.ErrorMessage = errorMessage;
                            customVal.ServerValidate += Contains;
                            this.Controls.Add(customVal);
                            break;
                    }

                    break;
            }

            this.Controls.Add(lbl_Instructions);
        }
示例#20
0
        private void AddControlNew(Property p, TabPage tp, string cap)
        {
            IDataType dt = p.PropertyType.DataTypeDefinition.DataType;
            dt.DataEditor.Editor.ID = string.Format("prop_{0}", p.PropertyType.Alias);
            dt.Data.PropertyId = p.Id;

            //Add the DataType to an internal dictionary, which will be used to call the save method on the IDataEditor
            //and to retrieve the value from IData in editContent.aspx.cs, so that it can be set on the legacy Document class.
            DataTypes.Add(p.PropertyType.Alias, dt);

            // check for buttons
            IDataFieldWithButtons df1 = dt.DataEditor.Editor as IDataFieldWithButtons;
            if (df1 != null)
            {
                ((Control)df1).ID = p.PropertyType.Alias;


                if (df1.MenuIcons.Length > 0)
                    tp.Menu.InsertSplitter();


                // Add buttons
                int c = 0;
                bool atEditHtml = false;
                bool atSplitter = false;
                foreach (object o in df1.MenuIcons)
                {
                    try
                    {
                        MenuIconI m = (MenuIconI)o;
                        MenuIconI mi = tp.Menu.NewIcon();
                        mi.ImageURL = m.ImageURL;
                        mi.OnClickCommand = m.OnClickCommand;
                        mi.AltText = m.AltText;
                        mi.ID = tp.ID + "_" + m.ID;

                        if (m.ID == "html")
                            atEditHtml = true;
                        else
                            atEditHtml = false;

                        atSplitter = false;
                    }
                    catch
                    {
                        tp.Menu.InsertSplitter();
                        atSplitter = true;
                    }

                    // Testing custom styles in editor
                    if (atSplitter && atEditHtml && dt.DataEditor.TreatAsRichTextEditor)
                    {
                        DropDownList ddl = tp.Menu.NewDropDownList();

                        ddl.Style.Add("margin-bottom", "5px");
                        ddl.Items.Add(ui.Text("buttons", "styleChoose", null));
                        ddl.ID = tp.ID + "_editorStyle";
                        if (StyleSheet.GetAll().Length > 0)
                        {
                            foreach (StyleSheet s in StyleSheet.GetAll())
                            {
                                foreach (StylesheetProperty sp in s.Properties)
                                {
                                    ddl.Items.Add(new ListItem(sp.Text, sp.Alias));
                                }
                            }
                        }
                        ddl.Attributes.Add("onChange", "addStyle(this, '" + p.PropertyType.Alias + "');");
                        atEditHtml = false;
                    }
                    c++;
                }
            }

            // check for element additions
            IMenuElement menuElement = dt.DataEditor.Editor as IMenuElement;
            if (menuElement != null)
            {
                // add separator
                tp.Menu.InsertSplitter();

                // add the element
                tp.Menu.NewElement(menuElement.ElementName, menuElement.ElementIdPreFix + p.Id.ToString(),
                                   menuElement.ElementClass, menuElement.ExtraMenuWidth);
            }

            Pane pp = new Pane();
            Control holder = new Control();
            holder.Controls.Add(dt.DataEditor.Editor);
            if (p.PropertyType.DataTypeDefinition.DataType.DataEditor.ShowLabel)
            {
                string caption = p.PropertyType.Name;
                if (p.PropertyType.Description != null && p.PropertyType.Description != String.Empty)
                    switch (UmbracoSettings.PropertyContextHelpOption)
                    {
                        case "icon":
                            caption += " <img src=\"" + this.ResolveUrl(SystemDirectories.Umbraco) + "/images/help.png\" class=\"umbPropertyContextHelp\" alt=\"" + p.PropertyType.Description + "\" title=\"" + p.PropertyType.Description + "\" />";
                            break;
                        case "text":
                            caption += "<br /><small>" + umbraco.library.ReplaceLineBreaks(p.PropertyType.Description) + "</small>";
                            break;
                    }
                pp.addProperty(caption, holder);
            }
            else
                pp.addProperty(holder);

            // Validation
            if (p.PropertyType.Mandatory)
            {
                try
                {
                    var rq = new RequiredFieldValidator
                        {
                            ControlToValidate = dt.DataEditor.Editor.ID,
                            CssClass = "error"
                        };
                    rq.Style.Add(HtmlTextWriterStyle.Display, "block");
                    rq.Style.Add(HtmlTextWriterStyle.Padding, "2px");
                    var component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate);
                    var attribute = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)];
                    PropertyDescriptor pd = null;
                    if (attribute != null)
                    {
                        pd = TypeDescriptor.GetProperties(component, null)[attribute.Name];
                    }
                    if (pd != null)
                    {
                        rq.EnableClientScript = false;
                        rq.Display = ValidatorDisplay.Dynamic;
                        string[] errorVars = { p.PropertyType.Name, cap };
                        rq.ErrorMessage = ui.Text("errorHandling", "errorMandatory", errorVars, null) + "<br/>";
                        holder.Controls.AddAt(0, rq);
                    }
                }
                catch (Exception valE)
                {
                    HttpContext.Current.Trace.Warn("contentControl",
                                                   "EditorControl (" + dt.DataTypeName + ") does not support validation",
                                                   valE);
                }
            }

            // RegExp Validation
            if (p.PropertyType.ValidationRegExp != "")
            {
                try
                {
                    var rv = new RegularExpressionValidator
                        {
                            ControlToValidate = dt.DataEditor.Editor.ID,
                            CssClass = "error"
                        };
                    rv.Style.Add(HtmlTextWriterStyle.Display, "block");
                    rv.Style.Add(HtmlTextWriterStyle.Padding, "2px");
                    var component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate);
                    var attribute = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)];
                    PropertyDescriptor pd = null;
                    if (attribute != null)
                    {
                        pd = TypeDescriptor.GetProperties(component, null)[attribute.Name];
                    }
                    if (pd != null)
                    {
                        rv.ValidationExpression = p.PropertyType.ValidationRegExp;
                        rv.EnableClientScript = false;
                        rv.Display = ValidatorDisplay.Dynamic;
                        string[] errorVars = { p.PropertyType.Name, cap };
                        rv.ErrorMessage = ui.Text("errorHandling", "errorRegExp", errorVars, null) + "<br/>";
                        holder.Controls.AddAt(0, rv);
                    }
                }
                catch (Exception valE)
                {
                    HttpContext.Current.Trace.Warn("contentControl",
                                                   "EditorControl (" + dt.DataTypeName + ") does not support validation",
                                                   valE);
                }
            }

            // This is once again a nasty nasty hack to fix gui when rendering wysiwygeditor
            if (dt.DataEditor.TreatAsRichTextEditor)
            {
                tp.Controls.Add(dt.DataEditor.Editor);
            }
            else
            {
                Panel ph = new Panel();
                ph.Attributes.Add("style", "padding: 0; position: relative;"); // NH 4.7.1, latest styles added to support CP item: 30363
                ph.Controls.Add(pp);

                tp.Controls.Add(ph);
            }
        }
示例#21
0
        /// <summary>
        /// 动态添加子表行和单元格以及单元格内各控件
        /// </summary>
        /// <param name="tab">当前单据子表</param>
        private void AddSonTableRows(Table tab)
        {
            //检测表是否存在
            if (tab == null)
            {
                return;
            }
            //新建子表的表头行
            var thr = new TableHeaderRow();
            thr.ID = "trHeadRow";
            thr.ClientIDMode = ClientIDMode.Static;
            thr.CssClass = "yd-head-tr";
            //表头行各单元格css
            string[] cssClasses =
                ("rowidtd,suppliercodetdth,suppliernametdth,materialcodetdth,materialnametdth,materialsizetdth," +
                "qtytdth,materialunittdth,pricetdth,remarktdth,operatetdth").Split(',');
            //表头行各单元格显示的文字
            string[] showTexts = "行号,供应商<br />代码,供应商名称,物料代码,物料名称,规格,数量,单位,单价<br />(元),备注,操作".Split(',');
            //为行添加单元格
            for (int i = 0; i < cssClasses.Length; i++)
            {
                //新建子表表头单元格
                var thc = new TableHeaderCell();
                thc.CssClass = cssClasses[i];
                thc.Text = showTexts[i];
                //添加到表头行
                thr.Cells.Add(thc);
            }
            //添加表头到表
            tab.Rows.Add(thr);

            //添加子表多个内容行
            for (int i = 0; i < 10; i++)
            {
                //新建子表内容行
                var tr = new TableRow();
                tr.ID = "trContentRow" + i;
                tr.ClientIDMode = ClientIDMode.Static;
                //当前列号
                int j = 0;

                //新建内容单元格
                var tc = new TableCell();
                tc.CssClass = "yd-center-td rowidtd";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", j.ToString());
                //内容行单元格控件
                //文字显示控件
                var lit = new Literal();
                lit.ID = "litRowId" + i;
                lit.ClientIDMode = ClientIDMode.Static;
                lit.Text = (i + 1).ToString();
                //添加控件到单元格
                tc.Controls.Add(lit);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-left-td suppliercodetdth";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                var tb = new TextBox();
                tb.ID = "txtSupplierCode" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "suppliercodetb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //验证控件
                var rev = new RegularExpressionValidator();
                rev.ID = "revSupplierCode" + i;
                rev.ErrorMessage = "*";
                rev.CssClass = "yd-validator";
                rev.SetFocusOnError = true;
                rev.Display = ValidatorDisplay.Dynamic;
                rev.ToolTip = "必须为1位大写字母加4位数字";
                rev.ControlToValidate = "txtSupplierCode" + i;
                rev.ValidationExpression = @"^[A-Z]\d{4}$";
                //添加控件到单元格
                tc.Controls.Add(rev);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-left-td suppliernametdth";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtSupplierName" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "suppliernametb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //验证控件
                var cv = new CustomValidator();
                cv.ID = "cvSupplierName" + i;
                cv.ErrorMessage = "*";
                cv.CssClass = "yd-validator";
                cv.SetFocusOnError = true;
                cv.Display = ValidatorDisplay.Dynamic;
                cv.ToolTip = "供应商名称不存在";
                cv.ControlToValidate = "txtSupplierName" + i;
                cv.ServerValidate += new ServerValidateEventHandler(cvSupplierName_ServerValidate);
                //添加控件到单元格
                tc.Controls.Add(cv);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-left-td materialcodetdth";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtMaterialCode" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "materialcodetb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //验证控件
                rev = new RegularExpressionValidator();
                rev.ID = "revMaterialCode" + i;
                rev.ErrorMessage = "*";
                rev.CssClass = "yd-validator";
                rev.SetFocusOnError = true;
                rev.Display = ValidatorDisplay.Dynamic;
                rev.ToolTip = "必须为1位大写字母加5位数字";
                rev.ControlToValidate = "txtMaterialCode" + i;
                rev.ValidationExpression = @"^[A-Z]\d{5}$";
                //添加控件到单元格
                tc.Controls.Add(rev);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-left-td materialnametdth";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtMaterialName" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "materialnametb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-center-td materialsizetdth";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtMaterialSize" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "materialsizetb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-right-td qtytdth";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtQty" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "qtytb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //验证控件
                rev = new RegularExpressionValidator();
                rev.ID = "revQty" + i; ;
                rev.ErrorMessage = "*";
                rev.CssClass = "yd-validator";
                rev.SetFocusOnError = true;
                rev.Display = ValidatorDisplay.Dynamic;
                rev.ToolTip = "必须为大于0的小数或整数,小数不能多余4位";
                rev.ControlToValidate = "txtQty" + i;
                rev.ValidationExpression =
                    @"^([1-9]\d{0,7}(\.\d{1,4})?|0\.(0{3}[1-9]|0{2}[1-9]\d?|0[1-9]\d{0,2}|[1-9]\d{0,3}))$";
                //添加控件到单元格
                tc.Controls.Add(rev);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-center-td materialunittdth";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtMaterialUnit" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "materialunittb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-right-td pricetdth";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                var hf = new HiddenField();
                hf.ID = "hfPrice" + i;
                hf.ClientIDMode = ClientIDMode.Static;
                //添加控件到单元格
                tc.Controls.Add(hf);
                //标签
                var lbl = new Label();
                lbl.ID = "lblPrice" + i;
                lbl.ClientIDMode = ClientIDMode.Static;
                lbl.CssClass = "pricelbl";
                //添加控件到单元格
                tc.Controls.Add(lbl);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-left-td remarktdth";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtRemark" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "remarktb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-center-td operatetdth";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //图片
                var img = new Image();
                img.ID = "imgClear" + i;
                img.ClientIDMode = ClientIDMode.Static;
                img.CssClass = "yd-img-clear";
                img.ToolTip = "清空本行";
                img.ImageUrl = "~/Images/Shared/delete.png";
                //添加控件到单元格
                tc.Controls.Add(img);
                //添加单元格到行
                tr.Cells.Add(tc);

                //添加行到表
                tab.Rows.Add(tr);
            }
        }
示例#22
0
        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            _regexValidator = new RegularExpressionValidator();
            _regexValidator.ID = this.ID + "_RE";
            _regexValidator.ControlToValidate = this.ID;
            _regexValidator.Display = ValidatorDisplay.Dynamic;
            _regexValidator.CssClass = "validation-error help-inline";
            _regexValidator.ValidationExpression = _regex;
            _regexValidator.ErrorMessage = "The link provided is not valid";
            Controls.Add( _regexValidator );
        }
示例#23
0
        private System.Web.UI.WebControls.BaseValidator GetValidator(Widget control, Core.BaseValidator validator)
        {
            System.Web.UI.WebControls.BaseValidator retVal = null;
            //string validationErrorMessage = null;
            //string validationResourceKeyPrefix = String.Format("", this.ResourceKeyPrefix, validator.Name)
            //validationErrorMessage = GetGlobalResourceString("", compareConfig.ErrorMessage);

            switch (validator.GetType().Name.ToLower())
            {
            case "comparevalidator":
                Core.CompareValidator compareConfig = (Core.CompareValidator)validator;
                System.Web.UI.WebControls.CompareValidator compareActual = new System.Web.UI.WebControls.CompareValidator();

                compareActual.ID      = compareConfig.Name;
                compareActual.Display = ValidatorDisplay.None;


                compareActual.ErrorMessage      = compareConfig.ErrorMessage;
                compareActual.Text              = "*";
                compareActual.ControlToValidate = control.Name;

                //validator specific
                compareActual.Type             = compareConfig.Type;
                compareActual.ControlToCompare = compareConfig.ControlToCompare;
                compareActual.Operator         = compareConfig.Operator;
                compareActual.ValueToCompare   = compareConfig.ValueToCompare;

                retVal = (System.Web.UI.WebControls.BaseValidator)compareActual;

                break;

            case "datacommandvalidator":
                Core.DataCommandValidator  dataConfig = (Core.DataCommandValidator)validator;
                CustomDataCommandValidator dataActual = new CustomDataCommandValidator();

                dataActual.ID      = dataConfig.Name;
                dataActual.Display = ValidatorDisplay.None;

                dataActual.ErrorMessage      = dataConfig.ErrorMessage;
                dataActual.Text              = "*";
                dataActual.ControlToValidate = control.Name;

                //validator specific
                dataActual.DataCommand          = dataConfig.DataCommand;
                dataActual.ValidationField      = dataConfig.ValidationField;
                dataActual.UseValueParameter    = dataConfig.UseValueParameter;
                dataActual.ValueParameter       = dataConfig.ValueParameter;
                dataActual.UseErrorMessageField = dataConfig.UseErrorMessageField;
                dataActual.ErrorMessageField    = dataConfig.ErrorMessageField;

                dataActual.ServerValidate += new ServerValidateEventHandler(DataCommandValidator_ServerValidate);

                retVal = (System.Web.UI.WebControls.BaseValidator)dataActual;
                break;

            case "regularexpressionvalidator":
                Core.RegularExpressionValidator regexpConfig = (Core.RegularExpressionValidator)validator;
                System.Web.UI.WebControls.RegularExpressionValidator regexpActual = new System.Web.UI.WebControls.RegularExpressionValidator();

                regexpActual.ID      = regexpConfig.Name;
                regexpActual.Display = ValidatorDisplay.None;

                regexpActual.ErrorMessage      = regexpConfig.ErrorMessage;
                regexpActual.Text              = "*";
                regexpActual.ControlToValidate = control.Name;

                //validator specific
                regexpActual.ValidationExpression = regexpConfig.ValidationExpression;

                retVal = (System.Web.UI.WebControls.BaseValidator)regexpActual;
                break;

            case "rangevalidator":
                Core.RangeValidator rangeConfig = (Core.RangeValidator)validator;
                System.Web.UI.WebControls.RangeValidator rangeActual = new System.Web.UI.WebControls.RangeValidator();

                rangeActual.ID      = rangeConfig.Name;
                rangeActual.Display = ValidatorDisplay.None;

                rangeActual.ErrorMessage      = rangeConfig.ErrorMessage;
                rangeActual.Text              = "*";
                rangeActual.ControlToValidate = control.Name;

                //validator specific
                rangeActual.Type         = rangeConfig.Type;
                rangeActual.MinimumValue = rangeConfig.MinimumValue;
                rangeActual.MaximumValue = rangeConfig.MaximumValue;

                retVal = (System.Web.UI.WebControls.BaseValidator)rangeActual;
                break;
            }

            return(retVal);
        }
 /// <include file='doc\RegularExpressionValidator.uex' path='docs/doc[@for="RegularExpressionValidator.CreateWebValidator"]/*' />
 protected override WebCntrls.BaseValidator CreateWebValidator()
 {
     _webRegularExpressionValidator = new WebCntrls.RegularExpressionValidator();
     return _webRegularExpressionValidator;
 }
			public void InstantiateIn (Control container) {
				Table table = new Table ();
				table.ControlStyle.Width = Unit.Percentage (100);
				table.ControlStyle.Height = Unit.Percentage (100);

				// Row #0
				table.Controls.Add (CreateRow (null, null, null, _createUserWizard.TitleTextStyle, null));

				// Row #1
				table.Controls.Add (CreateRow (null, null, null, _createUserWizard.InstructionTextStyle, null));

				// Row #2
				TextBox UserName = new TextBox ();
				UserName.ID = "UserName";
				_createUserWizard.RegisterApplyStyle (UserName, _createUserWizard.TextBoxStyle);

				Label UserNameLabel = new Label ();
				UserNameLabel.AssociatedControlID = "UserName";

				RequiredFieldValidator UserNameRequired = new RequiredFieldValidator ();
				UserNameRequired.ID = "UserNameRequired";
				// alternatively we can create only required validators
				// and reinstantiate collection when relevant property changes
				UserNameRequired.EnableViewState = false;
				UserNameRequired.ControlToValidate = "UserName";
				UserNameRequired.Text = "*";
				UserNameRequired.ValidationGroup = _createUserWizard.ID;
				_createUserWizard.RegisterApplyStyle (UserNameRequired, _createUserWizard.ValidatorTextStyle);

				table.Controls.Add (CreateRow (UserNameLabel, UserName, UserNameRequired, _createUserWizard.LabelStyle, null));

				// Row #3
				TextBox Password = new TextBox ();
				Password.ID = "Password";
				Password.TextMode = TextBoxMode.Password;
				_createUserWizard.RegisterApplyStyle (Password, _createUserWizard.TextBoxStyle);

				Label PasswordLabel = new Label ();
				PasswordLabel.AssociatedControlID = "Password";

				RequiredFieldValidator PasswordRequired = new RequiredFieldValidator ();
				PasswordRequired.ID = "PasswordRequired";
				PasswordRequired.EnableViewState = false;
				PasswordRequired.ControlToValidate = "Password";
				PasswordRequired.Text = "*";
				//PasswordRequired.EnableViewState = false;
				PasswordRequired.ValidationGroup = _createUserWizard.ID;
				_createUserWizard.RegisterApplyStyle (PasswordRequired, _createUserWizard.ValidatorTextStyle);

				table.Controls.Add (CreateRow (PasswordLabel, Password, PasswordRequired, _createUserWizard.LabelStyle, null));

				// Row #4
				table.Controls.Add (CreateRow (new LiteralControl (""), new LiteralControl (""), new LiteralControl (""), null, _createUserWizard.PasswordHintStyle));

				// Row #5
				TextBox ConfirmPassword = new TextBox ();
				ConfirmPassword.ID = "ConfirmPassword";
				ConfirmPassword.TextMode = TextBoxMode.Password;
				_createUserWizard.RegisterApplyStyle (ConfirmPassword, _createUserWizard.TextBoxStyle);

				Label ConfirmPasswordLabel = new Label ();
				ConfirmPasswordLabel.AssociatedControlID = "ConfirmPassword";

				RequiredFieldValidator ConfirmPasswordRequired = new RequiredFieldValidator ();
				ConfirmPasswordRequired.ID = "ConfirmPasswordRequired";
				ConfirmPasswordRequired.EnableViewState = false;
				ConfirmPasswordRequired.ControlToValidate = "ConfirmPassword";
				ConfirmPasswordRequired.Text = "*";
				ConfirmPasswordRequired.ValidationGroup = _createUserWizard.ID;
				_createUserWizard.RegisterApplyStyle (ConfirmPasswordRequired, _createUserWizard.ValidatorTextStyle);

				table.Controls.Add (CreateRow (ConfirmPasswordLabel, ConfirmPassword, ConfirmPasswordRequired, _createUserWizard.LabelStyle, null));

				// Row #6
				TextBox Email = new TextBox ();
				Email.ID = "Email";
				_createUserWizard.RegisterApplyStyle (Email, _createUserWizard.TextBoxStyle);

				Label EmailLabel = new Label ();
				EmailLabel.AssociatedControlID = "Email";

				RequiredFieldValidator EmailRequired = new RequiredFieldValidator ();
				EmailRequired.ID = "EmailRequired";
				EmailRequired.EnableViewState = false;
				EmailRequired.ControlToValidate = "Email";
				EmailRequired.Text = "*";
				EmailRequired.ValidationGroup = _createUserWizard.ID;
				_createUserWizard.RegisterApplyStyle (EmailRequired, _createUserWizard.ValidatorTextStyle);

				table.Controls.Add (CreateRow (EmailLabel, Email, EmailRequired, _createUserWizard.LabelStyle, null));

				// Row #7
				TextBox Question = new TextBox ();
				Question.ID = "Question";
				_createUserWizard.RegisterApplyStyle (Question, _createUserWizard.TextBoxStyle);

				Label QuestionLabel = new Label ();
				QuestionLabel.AssociatedControlID = "Question";

				RequiredFieldValidator QuestionRequired = new RequiredFieldValidator ();
				QuestionRequired.ID = "QuestionRequired";
				QuestionRequired.EnableViewState = false;
				QuestionRequired.ControlToValidate = "Question";
				QuestionRequired.Text = "*";
				QuestionRequired.ValidationGroup = _createUserWizard.ID;
				_createUserWizard.RegisterApplyStyle (QuestionRequired, _createUserWizard.ValidatorTextStyle);

				table.Controls.Add (CreateRow (QuestionLabel, Question, QuestionRequired, _createUserWizard.LabelStyle, null));

				// Row #8
				TextBox Answer = new TextBox ();
				Answer.ID = "Answer";
				_createUserWizard.RegisterApplyStyle (Answer, _createUserWizard.TextBoxStyle);

				Label AnswerLabel = new Label ();
				AnswerLabel.AssociatedControlID = "Answer";

				RequiredFieldValidator AnswerRequired = new RequiredFieldValidator ();
				AnswerRequired.ID = "AnswerRequired";
				AnswerRequired.EnableViewState = false;
				AnswerRequired.ControlToValidate = "Answer";
				AnswerRequired.Text = "*";
				AnswerRequired.ValidationGroup = _createUserWizard.ID;
				_createUserWizard.RegisterApplyStyle (AnswerRequired, _createUserWizard.ValidatorTextStyle);

				table.Controls.Add (CreateRow (AnswerLabel, Answer, AnswerRequired, _createUserWizard.LabelStyle, null));

				// Row #9
				CompareValidator PasswordCompare = new CompareValidator ();
				PasswordCompare.ID = "PasswordCompare";
				PasswordCompare.EnableViewState = false;
				PasswordCompare.ControlToCompare = "Password";
				PasswordCompare.ControlToValidate = "ConfirmPassword";
				PasswordCompare.Display = ValidatorDisplay.Static;
				PasswordCompare.ValidationGroup = _createUserWizard.ID;
				PasswordCompare.Display = ValidatorDisplay.Dynamic;
				_createUserWizard.RegisterApplyStyle (PasswordCompare, _createUserWizard.ValidatorTextStyle);

				table.Controls.Add (CreateRow (PasswordCompare, null, null, null, null));

				// Row #10
				RegularExpressionValidator PasswordRegEx = new RegularExpressionValidator ();
				PasswordRegEx.ID = "PasswordRegEx";
				PasswordRegEx.EnableViewState = false;
				PasswordRegEx.ControlToValidate = "Password";
				PasswordRegEx.Display = ValidatorDisplay.Static;
				PasswordRegEx.ValidationGroup = _createUserWizard.ID;
				PasswordRegEx.Display = ValidatorDisplay.Dynamic;
				_createUserWizard.RegisterApplyStyle (PasswordRegEx, _createUserWizard.ValidatorTextStyle);

				table.Controls.Add (CreateRow (PasswordRegEx, null, null, null, null));

				// Row #11
				RegularExpressionValidator EmailRegEx = new RegularExpressionValidator ();
				EmailRegEx.ID = "EmailRegEx";
				EmailRegEx.EnableViewState = false;
				EmailRegEx.ControlToValidate = "Email";
				EmailRegEx.Display = ValidatorDisplay.Static;
				EmailRegEx.ValidationGroup = _createUserWizard.ID;
				EmailRegEx.Display = ValidatorDisplay.Dynamic;
				_createUserWizard.RegisterApplyStyle (EmailRegEx, _createUserWizard.ValidatorTextStyle);

				table.Controls.Add (CreateRow (EmailRegEx, null, null, null, null));

				// Row #12
				Label ErrorMessage = new Label ();
				ErrorMessage.ID = "ErrorMessage";
				ErrorMessage.EnableViewState = false;
				_createUserWizard.RegisterApplyStyle (ErrorMessage, _createUserWizard.ValidatorTextStyle);

				table.Controls.Add (CreateRow (ErrorMessage, null, null, null, null));

				// Row #13
				TableRow row13 = CreateRow (new Image (), null, null, null, null);

				HyperLink HelpLink = new HyperLink ();
				HelpLink.ID = "HelpLink";
				_createUserWizard.RegisterApplyStyle (HelpLink, _createUserWizard.HyperLinkStyle);
				row13.Cells [0].Controls.Add (HelpLink);

				row13.Cells [0].HorizontalAlign = HorizontalAlign.Left;
				table.Controls.Add (row13);

				//
				container.Controls.Add (table);
			}
示例#26
0
        protected void Page_Load(object sender, EventArgs e)
        {
            TextBox nickNameBox = new TextBox() { ID = "nickNameBox" };
            TextBox nameBox = new TextBox() { ID = "nameBox" };
            TextBox sirNameBox = new TextBox() { ID = "sirNameBox" };
            TextBox emailBox = new TextBox { ID = "emailBox" };
            Label registrationFormLabel = new Label { Text = "Registration form:" };
            Label nicknameLabel = new Label { Text = "Nick Name:" };
            Label nameLabel = new Label { Text = "First name:" };
            Label sirnameLabel = new Label { Text = "Last name:" };
            Label dateOfBirthLabel = new Label { Text = "Date of birth:" };
            Label emailLabel = new Label { Text = "E-mail:" };
            Label countryLabel = new Label { Text = "Country:" };
            Label cityLabel = new Label { Text = "City:" };
            Label validationSummaryLabel = new Label { Text = "Validation Summary:" };

            RegularExpressionValidator emailvalidator = new RegularExpressionValidator() { ValidationExpression = @"[a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+", ControlToValidate = "emailBox", ForeColor = Color.Crimson, ErrorMessage = "Enter correct email please..." };
            RequiredFieldValidator requiredEmail = new RequiredFieldValidator() { ControlToValidate = "emailBox", ForeColor = Color.Crimson, ErrorMessage = "Enter e-mail please..." };
            RequiredFieldValidator requiredCountry = new RequiredFieldValidator() { ControlToValidate = "country", ForeColor = Color.Crimson, ErrorMessage = "Select country please..." };
            RequiredFieldValidator requiredCity = new RequiredFieldValidator() { ControlToValidate = "city", ForeColor = Color.Crimson, ErrorMessage = "Select city please..." };
            RequiredFieldValidator requiredNickname = new RequiredFieldValidator() { ControlToValidate = "nickNameBox", ForeColor = Color.Crimson, ErrorMessage = "Enter nickname please..." };
            RequiredFieldValidator requiredName = new RequiredFieldValidator() { ControlToValidate = "nameBox", ForeColor = Color.Crimson, ErrorMessage = "Enter first name please..." };
            RequiredFieldValidator requiredSirname = new RequiredFieldValidator() { ControlToValidate = "sirNameBox", ForeColor = Color.Crimson, ErrorMessage = "Enter last name please..." };
            RequiredFieldValidator requiredDate = new RequiredFieldValidator() { ControlToValidate = "birthDateBox", ForeColor = Color.Crimson, ErrorMessage = "Select the date please..." };
            CompareValidator nameToNick = new CompareValidator() { ControlToValidate = "nameBox", ControlToCompare = "nickNameBox", Operator = ValidationCompareOperator.NotEqual, ForeColor = Color.Crimson, ErrorMessage = "Shouldn`t be equal to nickname!" };
            CompareValidator sirnameToName = new CompareValidator() { ControlToValidate = "sirNameBox", ControlToCompare = "nameBox", Operator = ValidationCompareOperator.NotEqual, ForeColor = Color.Crimson, ErrorMessage = "Shouldn`t be equal to name!" };
            RangeValidator dateValidator = new RangeValidator() { ControlToValidate = "birthDateBox",MinimumValue = new DateTime(1960,12,1).ToShortDateString(),MaximumValue = DateTime.Now.ToShortDateString(),Type=ValidationDataType.Date, ForeColor = Color.Crimson, ErrorMessage = "Date of birth should be between 12/1/1960 and " + DateTime.Now.ToShortDateString() };
            CompareValidator notDefaultCountry = new CompareValidator() { ControlToValidate = "country", ValueToCompare = "Choose from there", Operator = ValidationCompareOperator.NotEqual, ForeColor = Color.Crimson, ErrorMessage = "Please select country!" };
            CompareValidator notDefaultCity = new CompareValidator() { ControlToValidate = "city", ValueToCompare = "Choose country first", Operator = ValidationCompareOperator.NotEqual, ForeColor = Color.Crimson, ErrorMessage = "Please, select city!" };

            ValidationSummary summary = new ValidationSummary() { ForeColor = Color.Crimson };

            Button submitButton = new Button();

            registrationFormLabel.Style["Position"] = "Absolute";
            registrationFormLabel.Style["Top"] = "25px";
            registrationFormLabel.Style["Left"] = "100px";
            registrationFormLabel.Font.Size = 24;
            registrationFormLabel.Font.Bold = true;

            nicknameLabel.Style["Position"] = "Absolute";
            nicknameLabel.Style["Top"] = "90px";
            nicknameLabel.Style["Left"] = "100px";
            nickNameBox.Style["Position"] = "Absolute";
            nickNameBox.Style["Top"] = "90px";
            nickNameBox.Style["Left"] = "250px";
            requiredNickname.Style["Position"] = "Absolute";
            requiredNickname.Style["Top"] = "90px";
            requiredNickname.Style["Left"] = "550px";

            nameLabel.Style["Position"] = "Absolute";
            nameLabel.Style["Top"] = "125px";
            nameLabel.Style["Left"] = "100px";
            nameBox.Style["Position"] = "Absolute";
            nameBox.Style["Top"] = "125px";
            nameBox.Style["Left"] = "250px";
            requiredName.Style["Position"] = "Absolute";
            requiredName.Style["Top"] = "125px";
            requiredName.Style["Left"] = "550px";
            nameToNick.Style["Position"] = "Absolute";
            nameToNick.Style["Top"] = "125px";
            nameToNick.Style["Left"] = "550px";

            sirnameLabel.Style["Position"] = "Absolute";
            sirnameLabel.Style["Top"] = "160px";
            sirnameLabel.Style["Left"] = "100px";
            sirNameBox.Style["Position"] = "Absolute";
            sirNameBox.Style["Top"] = "160px";
            sirNameBox.Style["Left"] = "250px";
            requiredSirname.Style["Position"] = "Absolute";
            requiredSirname.Style["Top"] = "160px";
            requiredSirname.Style["Left"] = "550px";
            sirnameToName.Style["Position"] = "Absolute";
            sirnameToName.Style["Top"] = "160px";
            sirnameToName.Style["Left"] = "550px";

            dateOfBirthLabel.Style["Position"] = "Absolute";
            dateOfBirthLabel.Style["Top"] = "195px";
            dateOfBirthLabel.Style["Left"] = "100px";
            birthDateBox.Style["Position"] = "Absolute";
            birthDateBox.Style["Top"] = "195px";
            birthDateBox.Style["Left"] = "250px";
            calendar.Style["Position"] = "Absolute";
            calendar.Style["Top"] = "230px";
            calendar.Style["Left"] = "250px";
            calendar.SelectionChanged += Calendar1_SelectionChanged;
            dateValidator.Style["Position"] = "Absolute";
            dateValidator.Style["Top"] = "195px";
            dateValidator.Style["Left"] = "550px";
            requiredDate.Style["Position"] = "Absolute";
            requiredDate.Style["Top"] = "195px";
            requiredDate.Style["Left"] = "550px";

            emailLabel.Style["Position"] = "Absolute";
            emailLabel.Style["Top"] = "425px";
            emailLabel.Style["Left"] = "100px";
            emailBox.Style["Position"] = "Absolute";
            emailBox.Style["Top"] = "425px";
            emailBox.Style["Left"] = "250px";
            emailvalidator.Style["Position"] = "Absolute";
            emailvalidator.Style["Top"] = "425px";
            emailvalidator.Style["Left"] = "550px";
            requiredEmail.Style["Position"] = "Absolute";
            requiredEmail.Style["Top"] = "425px";
            requiredEmail.Style["Left"] = "550px";

            countryLabel.Style["Position"] = "Absolute";
            countryLabel.Style["Top"] = "460px";
            countryLabel.Style["Left"] = "100px";
            country.Style["Position"] = "Absolute";
            country.Style["Top"] = "460px";
            country.Style["Left"] = "250px";
            requiredCountry.Style["Position"] = "Absolute";
            requiredCountry.Style["Top"] = "460px";
            requiredCountry.Style["Left"] = "550px";
            notDefaultCountry.Style["Position"] = "Absolute";
            notDefaultCountry.Style["Top"] = "460px";
            notDefaultCountry.Style["Left"] = "550px";
            country.Items.Add(new ListItem("Choose from there", "Choose from there"));
            country.Items.Add(new ListItem("Ukraine", "Ukraine"));
            country.Items.Add(new ListItem("Chech Republic", "Chech Republic"));
            country.SelectedIndexChanged += Country_ChangeSelection;
            country.AutoPostBack = true;

            cityLabel.Style["Position"] = "Absolute";
            cityLabel.Style["Top"] = "495px";
            cityLabel.Style["Left"] = "100px";
            city.Style["Position"] = "Absolute";
            city.Style["Top"] = "495px";
            city.Style["Left"] = "250px";
            requiredCity.Style["Position"] = "Absolute";
            requiredCity.Style["Top"] = "495px";
            requiredCity.Style["Left"] = "550px";
            city.Items.Add(new ListItem("Choose country first", "Choose country first"));
            notDefaultCity.Style["Position"] = "Absolute";
            notDefaultCity.Style["Top"] = "495px";
            notDefaultCity.Style["Left"] = "550px";

            validationSummaryLabel.Style["Position"] = "Absolute";
            validationSummaryLabel.Style["Top"] = "530px";
            validationSummaryLabel.Style["Left"] = "100px";
            summary.Style["Position"] = "Absolute";
            summary.Style["Top"] = "530px";
            summary.Style["Left"] = "250px";

            submitButton.Style["Position"] = "Absolute";
            submitButton.Style["Top"] = "600px";
            submitButton.Style["Left"] = "100px";
            submitButton.Text = "Submit";
            submitButton.Click += submitButton_Click;

            form1.Controls.Add(nickNameBox);
            form1.Controls.Add(nameBox);
            form1.Controls.Add(sirNameBox);
            form1.Controls.Add(birthDateBox);
            form1.Controls.Add(calendar);
            form1.Controls.Add(emailBox);
            form1.Controls.Add(country);
            form1.Controls.Add(city);
            form1.Controls.Add(submitButton);
            form1.Controls.Add(summary);
            form1.Controls.Add(registrationFormLabel);
            form1.Controls.Add(nicknameLabel);
            form1.Controls.Add(nameLabel);
            form1.Controls.Add(sirnameLabel);
            form1.Controls.Add(dateOfBirthLabel);
            form1.Controls.Add(emailLabel);
            form1.Controls.Add(countryLabel);
            form1.Controls.Add(cityLabel);
            form1.Controls.Add(validationSummaryLabel);
            form1.Controls.Add(emailvalidator);
            form1.Controls.Add(requiredEmail);
            form1.Controls.Add(requiredNickname);
            form1.Controls.Add(requiredName);
            form1.Controls.Add(requiredSirname);
            form1.Controls.Add(nameToNick);
            form1.Controls.Add(sirnameToName);
            form1.Controls.Add(dateValidator);
            form1.Controls.Add(requiredDate);
            form1.Controls.Add(requiredCountry);
            form1.Controls.Add(requiredCity);
            form1.Controls.Add(notDefaultCountry);
            form1.Controls.Add(notDefaultCity);
        }
 static public void WriteRegularExpressionValidator(HtmlTextWriter writer, RegularExpressionValidator rev, string className, string controlToValidate, string msg, string expression)
 {
     if (rev != null)
     {
         rev.CssClass = className;
         rev.ControlToValidate = controlToValidate;
         rev.ErrorMessage = msg;
         rev.ValidationExpression = expression;
         rev.RenderControl(writer);
     }
 }
        // This method create's validators for a particular column type. This should be as close to the the actual FieldTemplates (user controls) as possible.
        // DateTime -> Required, Regex
        // Integer -> Regex, Required, Range, Compare
        // Decimal -> Regex, Required, Range, Compare
        // Text -> Regex, Required
        // Enum -> Required
        private void CreateValidators(MetaColumn column) {
            if (_validators == null) {
                _validators = new List<BaseValidator>();
            }

            // Exclude regular expression validator for enum columns
            if (column.GetEnumType() == null) {
                RegularExpressionValidator regularExpressionValidator = new RegularExpressionValidator {
                    ControlToValidate = TextBoxID,
                    Enabled = false,
                    Display = ValidatorDisplay.Static,
                    CssClass = "DDControl DDValidator"
                };
                _validators.Add(regularExpressionValidator);
            }

            if (column.IsInteger || column.ColumnType == typeof(decimal) || column.ColumnType == typeof(double) || column.ColumnType == typeof(float)) {
                RangeValidator rangeValidator = new RangeValidator {
                    ControlToValidate = TextBoxID,
                    Enabled = false,
                    Display = ValidatorDisplay.Static,
                    MinimumValue = "0",
                    MaximumValue = "100",
                    CssClass = "DDControl DDValidator",
                    Type = column.IsInteger ? ValidationDataType.Integer : ValidationDataType.Double                    
                };
                _validators.Add(rangeValidator);

                CompareValidator compareValidator = new CompareValidator {
                    ControlToValidate = TextBoxID,
                    Enabled = false,
                    Display = ValidatorDisplay.Static,
                    Operator = ValidationCompareOperator.DataTypeCheck,
                    CssClass = "DDControl DDValidator",
                    Type = column.IsInteger ? ValidationDataType.Integer : ValidationDataType.Double
                };
                _validators.Add(compareValidator);
            }

            RequiredFieldValidator requiredFieldValidator = new RequiredFieldValidator {
                ControlToValidate = TextBoxID,
                Enabled = false,
                CssClass = "DDControl DDValidator",
                Display = ValidatorDisplay.Static
            };
            _validators.Add(requiredFieldValidator);


            DynamicValidator dynamicValidator = new DynamicValidator {
                ControlToValidate = TextBoxID,
                CssClass = "DDControl DDValidator",
                Display = ValidatorDisplay.Static
            };
            _validators.Add(dynamicValidator);
        }
示例#29
0
        private void BuildForm <T>(T instance)
        {
            var hidden = new System.Web.UI.WebControls.HiddenField();

            hidden.ID    = "__Type";
            hidden.Value = instance.ToString();
            Page.Form.Controls.Add(hidden);
            foreach (var property in instance.GetType().GetProperties())
            {
                var att = property.GetCustomAttributes(typeof(WebFormFieldAttribute), false);
                if (att != null && att.Length == 1)
                {
                    // create control.
                    var castAtt = (WebFormFieldAttribute)att[0];
                    var ctrl    = new System.Web.UI.WebControls.TextBox();
                    var label   = new System.Web.UI.WebControls.Label();
                    ctrl.ID = property.Name;
                    if (property.GetValue(instance, null) != null)
                    {
                        ctrl.Text = property.GetValue(instance, null).ToString();
                    }

                    var descriptionAtt = GettAttribute <DescriptionAttribute>(property);
                    if (descriptionAtt != null)
                    {
                        label.Text = descriptionAtt.Description;
                    }
                    else
                    {
                        label.Text = ctrl.ID;
                    }
                    Page.Form.Controls.Add(label);
                    Page.Form.Controls.Add(new Literal()
                    {
                        Text = "<br />"
                    });
                    Page.Form.Controls.Add(ctrl);

                    if (castAtt.IsRequired)
                    {
                        Page.Form.Controls.Add(new RequiredFieldValidator()
                        {
                            ID                = "reqValidate" + property.Name,
                            Text              = "*",
                            Display           = ValidatorDisplay.Static,
                            ControlToValidate = ctrl.ID
                        });
                    }

                    if (!string.IsNullOrEmpty(castAtt.RegexPattern))
                    {
                        var validator = new System.Web.UI.WebControls.RegularExpressionValidator();
                        validator.ID                   = "validate" + property.Name;
                        validator.Text                 = "*";
                        validator.Display              = ValidatorDisplay.Static;
                        validator.ControlToValidate    = ctrl.ID;
                        validator.ValidationExpression = castAtt.RegexPattern;
                        Page.Form.Controls.Add(validator);
                    }
                    Page.Form.Controls.Add(new Literal()
                    {
                        Text = "<br />"
                    });
                }
            }
            var submit = new System.Web.UI.WebControls.Button();

            submit.Text = "Submit";
            submit.UseSubmitBehavior = true;
            submit.Click            += new EventHandler(submit_Click);
            Page.Form.Controls.Add(submit);
        }
 public ValidatedInputControl(ValidatedInput vi)
 {
     field = vi;
     this.tb_ValidatedInput = new TextBox();
     this.regexVal = new RegularExpressionValidator();
 }
示例#31
0
        protected override void InitializeControls()
        {
            base.InitializeControls();

            panel = new Panel();

            HtmlGenericControl divSettingRow = new HtmlGenericControl("div");
            divSettingRow.Attributes.Add("class", "settingrow");

            HtmlGenericControl divButtonRow = new HtmlGenericControl("div");
            divButtonRow.Attributes.Add("class", "settingrow");

            Table table = new Table();
            TableRow exampleRow, inputRow;
            TableCell cell;
            exampleRow = new TableRow();
            table.Rows.Add(exampleRow);
            table.Rows.Add(inputRow = new TableRow());

            // top row
            cell = new TableCell();
            cell.Style[HtmlTextWriterStyle.Color] = "gray";
            cell.Style[HtmlTextWriterStyle.FontSize] = "smaller";
            requiredValidator = new RequiredFieldValidator();
            requiredValidator.ErrorMessage = RequiredTextDefault + RequiredTextSuffix;
            requiredValidator.Text = RequiredTextDefault + RequiredTextSuffix;
            requiredValidator.Display = ValidatorDisplay.Dynamic;
            requiredValidator.ControlToValidate = WrappedTextBox.ID;
            requiredValidator.ValidationGroup = ValidationGroupDefault;
            cell.Controls.Add(requiredValidator);
            uriFormatValidator = new RegularExpressionValidator();
            uriFormatValidator.ErrorMessage = UriFormatTextDefault + RequiredTextSuffix;
            uriFormatValidator.Text = UriFormatTextDefault + RequiredTextSuffix;
            uriFormatValidator.ValidationExpression = UriRegex;
            uriFormatValidator.Enabled = UriValidatorEnabledDefault;
            uriFormatValidator.Display = ValidatorDisplay.Dynamic;
            uriFormatValidator.ControlToValidate = WrappedTextBox.ID;
            uriFormatValidator.ValidationGroup = ValidationGroupDefault;
            cell.Controls.Add(uriFormatValidator);
            examplePrefixLabel = new Label();
            examplePrefixLabel.Text = ExamplePrefixDefault;
            cell.Controls.Add(examplePrefixLabel);
            cell.Controls.Add(new LiteralControl(" "));
            exampleUrlLabel = new Label();
            exampleUrlLabel.Font.Bold = true;
            exampleUrlLabel.Text = ExampleUrlDefault;
            cell.Controls.Add(exampleUrlLabel);
            exampleRow.Cells.Add(cell);

            //  row2
            buttonCell = new TableCell();
            buttonCell.Controls.Add(WrappedTextBox);
            inputRow.Cells.Add(buttonCell);

            loginButton = new Button();
            loginButton.ID = "loginButton";
            loginButton.Text = ButtonTextDefault;
            loginButton.ToolTip = ButtonToolTipDefault;
            loginButton.Click += new EventHandler(loginButton_Click);
            if (ValidationGroupDefault.Length > 0)
            {
                loginButton.ValidationGroup = ValidationGroupDefault;
            }
            #if !Mono
            panel.DefaultButton = loginButton.ID;
            #endif

            SiteLabel lbl = new SiteLabel();
            lbl.ForControl = WrappedTextBox.ID;
            lbl.ConfigKey = "OpenIDLabel";
            lbl.CssClass = "settinglabel";
            divSettingRow.Controls.Add(lbl);
            divSettingRow.Controls.Add(table);

            lbl = new SiteLabel();
            lbl.ConfigKey = "spacer";
            lbl.CssClass = "settinglabel";
            divButtonRow.Controls.Add(lbl);
            divButtonRow.Controls.Add(loginButton);

            panel.Controls.Add(divSettingRow);
            panel.Controls.Add(divButtonRow);
        }
		/// -----------------------------------------------------------------------------
		/// <summary>
		/// BuildValidators creates the validators part of the Control
		/// </summary>
		/// <param name="editInfo">The EditorInfo object for this control</param>
		/// <param name="targetId">Target Control Id.</param>
		/// <history>
		///     [cnurse]	05/08/2006	created
		/// </history>
		/// -----------------------------------------------------------------------------
		private void BuildValidators(EditorInfo editInfo, string targetId)
		{
			Validators.Clear();

			//Add Required Validators
			if (editInfo.Required)
			{
				var reqValidator = new RequiredFieldValidator();
				reqValidator.ID = editInfo.Name + "_Req";
				reqValidator.ControlToValidate = targetId;
				reqValidator.Display = ValidatorDisplay.Dynamic;
				reqValidator.ControlStyle.CopyFrom(ErrorStyle);
			    if(String.IsNullOrEmpty(reqValidator.CssClass))
			    {
			        reqValidator.CssClass = "dnnFormMessage dnnFormError";
			    }
				reqValidator.EnableClientScript = EnableClientValidation;
				reqValidator.Attributes.Add("resourcekey", editInfo.ResourceKey + ".Required");
				reqValidator.ErrorMessage = editInfo.Name + " is Required";
				Validators.Add(reqValidator);
			}
			
			//Add Regular Expression Validators
			if (!String.IsNullOrEmpty(editInfo.ValidationExpression))
			{
				var regExValidator = new RegularExpressionValidator();
				regExValidator.ID = editInfo.Name + "_RegEx";
				regExValidator.ControlToValidate = targetId;
				regExValidator.ValidationExpression = editInfo.ValidationExpression;
				regExValidator.Display = ValidatorDisplay.Dynamic;
				regExValidator.ControlStyle.CopyFrom(ErrorStyle);
			    if(String.IsNullOrEmpty(regExValidator.CssClass))
			    {
                    regExValidator.CssClass = "dnnFormMessage dnnFormError";
			    }
				regExValidator.EnableClientScript = EnableClientValidation;
				regExValidator.Attributes.Add("resourcekey", editInfo.ResourceKey + ".Validation");
				regExValidator.ErrorMessage = editInfo.Name + " is Invalid";
				Validators.Add(regExValidator);
			}
		}
示例#33
0
 private RegularExpressionValidator CreateRegExpValidator(string id, string controlToValidate)
 {
     try
     {
         RegularExpressionValidator regExp = new RegularExpressionValidator();
         regExp.ID = id;
         regExp.ControlToValidate = controlToValidate;
         regExp.ValidationGroup = "grpUserBeforeNewQuestions";
         regExp.ValidationExpression = "^[\\d]*$";
         regExp.CssClass = "form_field_error_message";
         regExp.Text = "Solo puede ingresar números";
         regExp.Display = ValidatorDisplay.Dynamic;
         return regExp;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#34
0
        /// <summary>
        /// 动态添加子表行和单元格以及单元格内各控件
        /// </summary>
        /// <param name="tab">当前单据子表</param>
        private void AddSonTableRows(Table tab)
        {
            //检测表是否存在
            if (tab == null)
            {
                return;
            }
            //新建子表的表头行
            var thr = new TableHeaderRow();
            thr.ID = "trHeadRow";
            thr.ClientIDMode = ClientIDMode.Static;
            thr.CssClass = "yd-head-tr";
            //表头行各单元格css
            string[] cssClasses = "rowidtd,prevprocnametd,lotidtd,productnumtd,pnlqtytd,pcsqtytd,remarktd,operatetd".Split(',');
            //表头行各单元格显示的文字
            string[] showTexts = "行号,上部门名称,批量卡号,生产编号,pnl数量,pcs数量,备注,操作".Split(',');
            //为行添加单元格
            for (int i = 0; i < cssClasses.Length; i++)
            {
                //新建子表表头单元格
                var thc = new TableHeaderCell();
                thc.CssClass = cssClasses[i];
                thc.Text = showTexts[i];
                //添加到表头行
                thr.Cells.Add(thc);
            }
            //添加表头到表
            tab.Rows.Add(thr);

            //添加子表多个内容行
            for (int i = 0; i < 10; i++)
            {
                //新建子表内容行
                var tr = new TableRow();
                tr.ID = "trContentRow" + i;
                tr.ClientIDMode = ClientIDMode.Static;
                //当前列号
                int j = 0;

                //新建内容单元格
                var tc = new TableCell();
                tc.CssClass = "yd-center-td rowidtd";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", j.ToString());
                //内容行单元格控件
                //文字显示控件
                var lit = new Literal();
                lit.ID = "litRowId" + i;
                lit.ClientIDMode = ClientIDMode.Static;
                lit.Text = (i + 1).ToString();
                //添加控件到单元格
                tc.Controls.Add(lit);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-center-td prevprocnametd";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", j.ToString());
                //内容行单元格控件
                //文字显示控件
                var tb = new TextBox();
                tb.ID = "txtPrevProcName" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "prevprocnametb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //添加单元格到行
                tr.Cells.Add(tc);
                //验证控件
                var cv = new CustomValidator();
                cv.ID = "cvPrevProcName" + i; ;
                cv.ErrorMessage = "*";
                cv.CssClass = "yd-validator";
                cv.SetFocusOnError = true;
                cv.Display = ValidatorDisplay.Dynamic;
                cv.ToolTip = "上部门名称不正确";
                cv.ControlToValidate = "txtPrevProcName" + i;
                cv.ServerValidate += cvPrevProcName_ServerValidate;
                //添加控件到单元格
                tc.Controls.Add(cv);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-left-td lotidtd";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtLotId" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "lotidtb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //验证控件
                var rev = new RegularExpressionValidator();
                rev.ID = "revLotId" + i;
                rev.ErrorMessage = "*";
                rev.CssClass = "yd-validator";
                rev.SetFocusOnError = true;
                rev.Display = ValidatorDisplay.Dynamic;
                rev.ToolTip = "必须为两位年份两位月份-最多5位整数,样板要在-后面添加S";
                rev.ControlToValidate = "txtLotId" + i;
                rev.ValidationExpression = @"^[1-9]\d(0[1-9]|1[012])-S?[1-9]\d{0,4}$";
                //添加控件到单元格
                tc.Controls.Add(rev);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-left-td productnumtd";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtProductNum" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "productnumtb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //验证控件
                cv = new CustomValidator();
                cv.ID = "revProductNum" + i; ;
                cv.ErrorMessage = "*";
                cv.CssClass = "yd-validator";
                cv.SetFocusOnError = true;
                cv.Display = ValidatorDisplay.Dynamic;
                cv.ToolTip = "只允许版本号与订单生产编号不相同";
                cv.ControlToValidate = "txtProductNum" + i;
                cv.ServerValidate += cvProductNum_ServerValidate;
                //添加控件到单元格
                tc.Controls.Add(cv);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-right-td pnlqtytd";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtPnlQty" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "pnlqtytb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //验证控件
                rev = new RegularExpressionValidator();
                rev.ID = "revPnlQty" + i; ;
                rev.ErrorMessage = "*";
                rev.CssClass = "yd-validator";
                rev.SetFocusOnError = true;
                rev.Display = ValidatorDisplay.Dynamic;
                rev.ToolTip = "必须为大于0的纯数字或为空";
                rev.ControlToValidate = "txtPnlQty" + i;
                rev.ValidationExpression = @"^[1-9]\d*$";
                //添加控件到单元格
                tc.Controls.Add(rev);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-right-td pcsqtytd";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtPcsQty" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "pcsqtytb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //验证控件
                rev = new RegularExpressionValidator();
                rev.ID = "revPcsQty" + i; ;
                rev.ErrorMessage = "*";
                rev.CssClass = "yd-validator";
                rev.SetFocusOnError = true;
                rev.Display = ValidatorDisplay.Dynamic;
                rev.ToolTip = "必须为大于0的纯数字或为空";
                rev.ControlToValidate = "txtPcsQty" + i;
                rev.ValidationExpression = @"^[1-9]\d*$";
                //添加控件到单元格
                tc.Controls.Add(rev);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-left-td remarktd";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //文本框
                tb = new TextBox();
                tb.ID = "txtRemark" + i;
                tb.ClientIDMode = ClientIDMode.Static;
                tb.CssClass = "remarktb";
                //添加控件到单元格
                tc.Controls.Add(tb);
                //添加单元格到行
                tr.Cells.Add(tc);

                //新建内容单元格
                tc = new TableCell();
                tc.CssClass = "yd-center-td operatetd";
                tc.Attributes.Add("data-yd-row-index", i.ToString());
                tc.Attributes.Add("data-yd-col-index", (++j).ToString());
                //内容行单元格控件
                //图片
                var img = new Image();
                img.ID = "imgClear" + i;
                img.ClientIDMode = ClientIDMode.Static;
                img.CssClass = "yd-img-clear";
                img.ToolTip = "清空本行";
                img.ImageUrl = "~/Images/Shared/delete.png";
                //添加控件到单元格
                tc.Controls.Add(img);
                //添加单元格到行
                tr.Cells.Add(tc);

                //添加行到表
                tab.Rows.Add(tr);
            }
        }
示例#35
0
文件: NumberBox.cs 项目: uncas/hibes
        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            numberTextBox = new TextBox();
            numberTextBox.ID = "tbNumber";

            revNumber = new RegularExpressionValidator();
            revNumber.ControlToValidate = numberTextBox.ID;
            revNumber.Text = "?";
            revNumber.ToolTip = "Indtast et gyldigt tal";

            SetValidationExpression();

            this.Controls.Add(numberTextBox);

            base.CreateChildControls();
        }