protected void Page_Load(object sender, EventArgs e) { // Create extender NumericUpDownExtender exNumeric = new NumericUpDownExtender(); exNumeric.ID = "exNum"; exNumeric.TargetControlID = textbox.ID; exNumeric.EnableViewState = false; Controls.Add(exNumeric); // Initialize extender exNumeric.Minimum = Minimum; exNumeric.Maximum = Maximum; exNumeric.Step = Step; exNumeric.Width = Width; // Disable checking changes before complete initialization textbox.Attributes.Add("data-ignorechanges", "true"); textbox.Width = Width; exNumeric.TargetButtonUpID = btnUp.ID; exNumeric.TargetButtonDownID = btnDown.ID; LoadValues(); if ((mValues != null) && (mValues.Count > 0)) { exNumeric.RefValues = String.Join(";", mValues.Keys); } // Initialize up button if (!string.IsNullOrEmpty(UpButtonImageUrl)) { btnImgUp.Visible = true; btnUp.Visible = false; btnImgUp.ImageUrl = UpButtonImageUrl; btnImgUp.AlternateText = ContextResolver.ResolveMacros(UpButtonImageAlternateText); btnImgUp.ImageAlign = ImageAlign.Middle; exNumeric.TargetButtonUpID = btnImgUp.ID; } // Initialize down button if (!string.IsNullOrEmpty(DownButtonImageUrl)) { btnImgDown.Visible = true; btnDown.Visible = false; btnImgDown.ImageUrl = DownButtonImageUrl; btnImgDown.AlternateText = ContextResolver.ResolveMacros(DownButtonImageAlternateText); btnImgDown.ImageAlign = ImageAlign.Middle; exNumeric.TargetButtonDownID = btnImgDown.ID; } exNumeric.ServiceDownMethod = ServiceDownMethod; exNumeric.ServiceDownPath = ServiceDownPath; exNumeric.ServiceUpMethod = ServiceUpMethod; exNumeric.ServiceUpPath = ServiceUpPath; exNumeric.Tag = ContextResolver.ResolveMacros(Tag); // Apply CSS styles if (!String.IsNullOrEmpty(CssClass)) { pnlContainer.CssClass = CssClass; CssClass = null; } if (!String.IsNullOrEmpty(ControlStyle)) { pnlContainer.Attributes.Add("style", ControlStyle); ControlStyle = null; } CheckRegularExpression = true; CheckFieldEmptiness = true; }
protected void Page_Load(object sender, EventArgs e) { // Create extender NumericUpDownExtender exNumeric = new NumericUpDownExtender(); exNumeric.ID = "exNum"; exNumeric.TargetControlID = textbox.ID; exNumeric.EnableViewState = false; Controls.Add(exNumeric); // Initialize extender exNumeric.Minimum = Minimum; exNumeric.Maximum = Maximum; exNumeric.Step = Step; exNumeric.Width = Width; LoadValues(); if ((values != null) && (values.Count > 0)) { string refValues = null; foreach (string key in values.Keys) { refValues += key + ";"; } exNumeric.RefValues = refValues.TrimEnd(';'); } // Initialize up button if (!string.IsNullOrEmpty(UpButtonImageUrl)) { btnUp.Visible = true; btnUp.ImageUrl = UpButtonImageUrl; btnUp.AlternateText = CMSContext.CurrentResolver.ResolveMacros(UpButtonImageAlternateText); btnUp.ImageAlign = ImageAlign.Middle; exNumeric.TargetButtonUpID = btnUp.ID; } // Initialize down button if (!string.IsNullOrEmpty(DownButtonImageUrl)) { btnDown.Visible = true; btnDown.ImageUrl = DownButtonImageUrl; btnDown.AlternateText = CMSContext.CurrentResolver.ResolveMacros(DownButtonImageAlternateText); btnDown.ImageAlign = ImageAlign.Middle; exNumeric.TargetButtonDownID = btnDown.ID; } exNumeric.ServiceDownMethod = ServiceDownMethod; exNumeric.ServiceDownPath = ServiceDownPath; exNumeric.ServiceUpMethod = ServiceUpMethod; exNumeric.ServiceUpPath = ServiceUpPath; exNumeric.Tag = CMSContext.CurrentResolver.ResolveMacros(Tag); // Apply CSS styles if (!String.IsNullOrEmpty(this.CssClass)) { pnlContainer.CssClass = this.CssClass; this.CssClass = null; } if (!String.IsNullOrEmpty(this.ControlStyle)) { pnlContainer.Attributes.Add("style", this.ControlStyle); this.ControlStyle = null; } this.CheckRegularExpression = true; this.CheckFieldEmptiness = true; }
protected TableRow newSubjectRow(Model.CCOM.Subject model) { int level = model.Subject_level; int subjectId = model.Subject_id; //当前项TableRow TableRow subjectRow = new TableRow(); TableCell titleCell = new TableCell(); subjectRow.Cells.Add(titleCell); //空格 Label span = new Label(); string blank = ""; for (int i = 0; i < model.Subject_level; i++) { blank += " "; } span.Text = blank; titleCell.Controls.Add(span); //加减号 ImageButton symbol = new ImageButton(); symbol.ID = "symbol" + subjectId; symbol.ImageUrl = "../../../images/exam/minus.png"; symbol.Click += symbol_Click; symbol.CausesValidation = false; symbol.Width = 10; titleCell.Controls.Add(symbol); Label space = new Label(); space.Text = " "; titleCell.Controls.Add(space); TableCell valueTypeCell = new TableCell(); valueTypeCell.HorizontalAlign = HorizontalAlign.Center; subjectRow.Cells.Add(valueTypeCell); TableCell subjectTypeCell = new TableCell(); subjectTypeCell.HorizontalAlign = HorizontalAlign.Center; subjectRow.Cells.Add(subjectTypeCell); TableCell manageAgencyCell = new TableCell(); manageAgencyCell.HorizontalAlign = HorizontalAlign.Center; subjectRow.Cells.Add(manageAgencyCell); TableCell weightCell = new TableCell(); weightCell.HorizontalAlign = HorizontalAlign.Center; subjectRow.Cells.Add(weightCell); TableCell descriptionCell = new TableCell(); descriptionCell.HorizontalAlign = HorizontalAlign.Center; subjectRow.Cells.Add(descriptionCell); TableCell btnCell = new TableCell(); btnCell.HorizontalAlign = HorizontalAlign.Center; subjectRow.Cells.Add(btnCell); HiddenField attachRow = new HiddenField(); attachRow.ID = "attachRow" + subjectId; btnCell.Controls.Add(attachRow); if (level == 0) { //标题 Label title = new Label(); title.ID = "title" + subjectId; title.Text = ddlMajor.SelectedItem.Text + "专业科目"; titleCell.Controls.Add(title); } else { //标题 TextBox title = new TextBox(); title.ID = "title" + subjectId; title.Text = model.Subject_title; title.Attributes.Add("OnFocus", "if(this.value=='请输入标题') {this.value=''}"); title.Attributes.Add("OnBlur", "if(this.value==''){this.value='请输入标题'}"); title.Attributes.Add("OnChange", "document.getElementById('btnSave').className='btn btn-success';document.getElementById('labelSave').innerHTML='内容已变更,请保存';"); titleCell.Controls.Add(title); RequiredFieldValidator titleValidator = new RequiredFieldValidator(); titleValidator.ControlToValidate = "title" + subjectId; titleValidator.ID = "titleValidator" + subjectId; titleValidator.Display = ValidatorDisplay.Dynamic; titleValidator.ErrorMessage = "请输入标题"; titleValidator.InitialValue = "请输入标题"; titleCell.Controls.Add(titleValidator); CustomValidator CtitleValidator = new CustomValidator(); CtitleValidator.ControlToValidate = "title" + subjectId; CtitleValidator.ID = "CtitleValidator" + subjectId; CtitleValidator.Display = ValidatorDisplay.Dynamic; CtitleValidator.ServerValidate += invalid_ServerValidate; CtitleValidator.ErrorMessage = "请勿输入非法字符"; titleCell.Controls.Add(CtitleValidator); //值方式 DropDownList valueType = new DropDownList(); valueType.ID = "valueType" + subjectId; if (model.Subject_level <= 5) { valueType.Items.Add(new ListItem("多项", "0")); valueType.Items.Add(new ListItem("单选", "1")); valueType.Items.Add(new ListItem("多选", "2")); } valueType.Items.Add(new ListItem("文本", "3")); valueType.Items.Add(new ListItem("不填", "4")); valueType.SelectedValue = model.Value_type.ToString(); valueType.Width = 70; valueType.SelectedIndexChanged += valueType_SelectedIndexChanged; valueType.AutoPostBack = true; valueTypeCell.Controls.Add(valueType); Label label1 = new Label(); label1.ID = "label1" + subjectId; label1.Text = " "; label1.Visible = false; valueTypeCell.Controls.Add(label1); TextBox valueCount = new TextBox(); valueCount.ID = "valueCount" + subjectId; valueCount.Text = "2"; valueCount.Enabled = false; valueCount.Width = 20; valueCount.Visible = false; valueTypeCell.Controls.Add(valueCount); ImageButton btnValueCountUp = new ImageButton(); btnValueCountUp.ID = "btnValueCountUp" + subjectId; btnValueCountUp.Width = 12; btnValueCountUp.Style["position"] = "relative"; btnValueCountUp.Style["top"] = "-8px"; btnValueCountUp.Style["left"] = "2px"; btnValueCountUp.ImageUrl = "../../../images/exam/add.png"; btnValueCountUp.Visible = false; btnValueCountUp.CausesValidation = false; valueTypeCell.Controls.Add(btnValueCountUp); ImageButton btnValueCountDown = new ImageButton(); btnValueCountDown.ID = "btnValueCountDown" + subjectId; btnValueCountDown.Width = 12; btnValueCountDown.Style["position"] = "relative"; btnValueCountDown.Style["top"] = "8px"; btnValueCountDown.Style["left"] = "-10px"; btnValueCountDown.ImageUrl = "../../../images/exam/minus.png"; btnValueCountDown.Visible = false; btnValueCountDown.CausesValidation = false; valueTypeCell.Controls.Add(btnValueCountDown); NumericUpDownExtender valueCountUpDown = new NumericUpDownExtender(); valueCountUpDown.TargetControlID = "valueCount" + subjectId; valueCountUpDown.Maximum = 10; valueCountUpDown.Minimum = 2; valueCountUpDown.TargetButtonUpID = "btnValueCountUp" + subjectId; valueCountUpDown.TargetButtonDownID = "btnValueCountDown" + subjectId; valueTypeCell.Controls.Add(valueCountUpDown); Label label2 = new Label(); label2.ID = "label2" + subjectId; label2.Text = "项"; label2.Visible = false; valueTypeCell.Controls.Add(label2); CustomValidator lackSonValidator = new CustomValidator(); lackSonValidator.ControlToValidate = "valueType" + subjectId; lackSonValidator.ID = "lackSonValidator" + subjectId; lackSonValidator.Display = ValidatorDisplay.Dynamic; lackSonValidator.ServerValidate += lackSonValidator_ServerValidate; lackSonValidator.ErrorMessage = "缺少子项目"; valueTypeCell.Controls.Add(lackSonValidator); CustomValidator errorSonValidator = new CustomValidator(); errorSonValidator.ControlToValidate = "valueType" + subjectId; errorSonValidator.ID = "errorSonValidator" + subjectId; errorSonValidator.Display = ValidatorDisplay.Dynamic; errorSonValidator.ServerValidate += errorSonValidator_ServerValidate; errorSonValidator.ErrorMessage = "多选子项只可以为文本或不填"; valueTypeCell.Controls.Add(errorSonValidator); if (level == 1 || level == 2) { if (level == 2) { //笔试/面试 DropDownList subjectType = new DropDownList(); subjectType.ID = "subjectType" + subjectId; subjectType.Items.Insert(0, "笔试"); subjectType.Items.Insert(1, "面试"); subjectType.Width = 70; subjectType.SelectedIndex = (Convert.ToBoolean(model.Subject_type) ? 1 : 0); subjectTypeCell.Controls.Add(subjectType); DropDownList manageAgency = new DropDownList(); manageAgency.ID = "manageAgency" + subjectId; BindAgency(manageAgency); manageAgency.Width = 140; manageAgency.SelectedValue = model.Manage_Agency_id.ToString(); manageAgencyCell.Controls.Add(manageAgency); } //权值 TextBox weight = new TextBox(); weight.ID = "weight" + subjectId; weight.Width = 30; weight.Text = model.Subject_weight.ToString(); weight.Enabled = false; weightCell.Controls.Add(weight); ImageButton btnWeightUp = new ImageButton(); btnWeightUp.ID = "btnWeightUp" + subjectId; btnWeightUp.Width = 12; btnWeightUp.Style["position"] = "relative"; btnWeightUp.Style["top"] = "-8px"; btnWeightUp.Style["left"] = "2px"; btnWeightUp.ImageUrl = "../../../images/exam/add.png"; weightCell.Controls.Add(btnWeightUp); ImageButton btnWeightDown = new ImageButton(); btnWeightDown.ID = "btnWeightDown" + subjectId; btnWeightDown.Width = 12; btnWeightDown.Style["position"] = "relative"; btnWeightDown.Style["top"] = "8px"; btnWeightDown.Style["left"] = "-10px"; btnWeightDown.ImageUrl = "../../../images/exam/minus.png"; weightCell.Controls.Add(btnWeightDown); NumericUpDownExtender weightUpDown = new NumericUpDownExtender(); weightUpDown.TargetControlID = "weight" + subjectId; weightUpDown.Maximum = 10; weightUpDown.Minimum = 0; weightUpDown.TargetButtonUpID = "btnWeightUp" + subjectId; weightUpDown.TargetButtonDownID = "btnWeightDown" + subjectId; weightCell.Controls.Add(weightUpDown); } TextBox description = new TextBox(); description.ID = "description" + subjectId; description.TextMode = TextBoxMode.MultiLine; description.Rows = 2; description.Width = 150; description.Text = model.Subject_description.ToString(); descriptionCell.Controls.Add(description); CustomValidator CdescriptionValidator = new CustomValidator(); CdescriptionValidator.ControlToValidate = "description" + subjectId; CdescriptionValidator.ID = "CdescriptionValidator" + subjectId; CdescriptionValidator.Display = ValidatorDisplay.Dynamic; CdescriptionValidator.ServerValidate += invalid_ServerValidate; CdescriptionValidator.ErrorMessage = "请勿输入非法字符"; descriptionCell.Controls.Add(CdescriptionValidator); } //按钮 if (level != 0) { Button btnDelete = new Button(); btnDelete.ID = "btnDelete" + subjectId; btnDelete.Text = "删除"; btnDelete.Click += btnDelete_Click; btnDelete.CssClass = "btn"; btnDelete.CausesValidation = false; btnCell.Controls.Add(btnDelete); } if (level <= 5) { Button btnAdd = new Button(); btnAdd.ID = "btnAdd" + subjectId; btnAdd.Text = "新建"; btnAdd.Click += btnAdd_Click; btnAdd.CssClass = "btn"; btnAdd.CausesValidation = false; btnCell.Controls.Add(btnAdd); } return(subjectRow); }