protected void Page_Load(object sender, EventArgs e) { HttpCookie userCookie; HttpCookie passCookie; userCookie = Request.Cookies["UserID"]; passCookie = Request.Cookies["UserPass"]; if (userCookie == null || passCookie == null) { Response.Redirect("../Account/Login.aspx"); } else { User_Class usuario_sesion = new User_Class(); usuario_sesion = usuario_sesion.getUser(userCookie.Value); if (usuario_sesion.Pass == passCookie.Value) { CompareValidator pass = new CompareValidator(); pass.ID = "CorrectPasswordCompare"; pass.ValueToCompare = usuario_sesion.Pass; pass.ControlToValidate = "CurrentPassword"; pass.CssClass = "failureNotification"; pass.ErrorMessage = "*</br>The passwords is not correct."; CurrentPasswordRequired.Controls.Add(pass); } else { Response.Redirect("../Account/Login.aspx"); } } }
private static CompareValidator GetDecimalValidator(Control controlToValidate, string domain, string cssClass) { using (CompareValidator validator = new CompareValidator()) { validator.ID = controlToValidate.ID + "DecimalValidator"; validator.ErrorMessage = @"<br/>" + Titles.OnlyNumbersAllowed; validator.CssClass = cssClass; validator.ControlToValidate = controlToValidate.ID; validator.EnableClientScript = true; validator.SetFocusOnError = true; validator.Display = ValidatorDisplay.Dynamic; validator.Type = ValidationDataType.Currency; //MixERP strict data type if (domain.EndsWith("strict")) { validator.Operator = ValidationCompareOperator.GreaterThan; } else { validator.Operator = ValidationCompareOperator.GreaterThanEqual; } validator.ValueToCompare = "0"; return validator; } }
protected override void CreateChildControls() { this.Controls.Clear(); textBox = new TextBox(); textBox.ID = this.ID; extender = new CalendarExtender(); extender.ID = this.ID + "CalendarExtender"; extender.Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; extender.TodaysDateFormat = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern; extender.TargetControlID = textBox.ClientID; extender.PopupButtonID = textBox.ClientID; validator = new CompareValidator(); validator.Display = ValidatorDisplay.Dynamic; validator.ID = this.ID + "CompareValidator"; validator.ControlToValidate = this.ID; validator.ValueToCompare = "1/1/1900"; validator.Type = ValidationDataType.Date; validator.ErrorMessage = Resources.CommonResource.InvalidDate; validator.EnableClientScript = true; validator.CssClass = this.ValidatorCssClass; this.Controls.Add(textBox); this.Controls.Add(extender); if(this.EnableValidation) { this.Controls.Add(validator); } }
protected override void InitializeDataCell(DataControlFieldCell cell, DataControlRowState rowState) { //base.InitializeDataCell(cell, rowState); TextBox textBox = new TextBox(); textBox.ID = this.ControlID; textBox.Width = new Unit(GridColumn.Width, UnitType.Pixel); if (GridColumn.Size != 0) textBox.MaxLength = GridColumn.Size; textBox.DataBinding += new EventHandler(this.textBox_DataBinding); base.InitializeDataCell(cell, rowState); cell.Controls.Add(textBox); CompareValidator vld = new CompareValidator(); vld.ControlToValidate = textBox.ID; vld.ID = textBox.ID + "vld"; vld.Operator = ValidationCompareOperator.DataTypeCheck; vld.ErrorMessage = "не верный формат (2)"; vld.Text = "! (2)"; vld.Display = ValidatorDisplay.Dynamic; if (GridColumn.Type == typeof(int)) vld.Type = ValidationDataType.Integer; if (GridColumn.Type == typeof(decimal)) vld.Type = ValidationDataType.Double; if (GridColumn.Type == typeof(string)) vld.Type = ValidationDataType.String; cell.Controls.Add(vld); if (!GridColumn.AllowNULL) { RequiredFieldValidator reqvld = new RequiredFieldValidator(); reqvld.ControlToValidate = textBox.ID; reqvld.ID = textBox.ID + "reqvld"; reqvld.ErrorMessage = "поле не может быть пустым (1)"; reqvld.Text = "! (1)"; reqvld.Display = ValidatorDisplay.Dynamic; cell.Controls.Add(reqvld); } }
private static CompareValidator GetDecimalValidator(Control controlToValidate, string domain) { using (CompareValidator validator = new CompareValidator()) { validator.ID = controlToValidate.ID + "DecimalValidator"; validator.ErrorMessage = "<br/>" + Resources.ScrudResource.OnlyNumbersAllowed; validator.CssClass = "form-error"; validator.ControlToValidate = controlToValidate.ID; validator.EnableClientScript = true; validator.SetFocusOnError = true; validator.Display = ValidatorDisplay.Dynamic; validator.Type = ValidationDataType.Double; //MixERP strict data type if (domain.Contains("strict")) { validator.Operator = ValidationCompareOperator.GreaterThan; } else { validator.Operator = ValidationCompareOperator.GreaterThanEqual; } validator.ValueToCompare = "0"; return validator; } }
public DynamicDatePicker() { _textBox = new TextBox(); _textBox.CausesValidation = false; _textBox.Width = Unit.Pixel(70); _maskEditExtender = new MaskedEditExtender(); _maskEditExtender.ClearMaskOnLostFocus = true; _maskEditValidator = new MaskedEditValidator(); _maskEditValidator.Display = ValidatorDisplay.Dynamic; _maskEditValidator.EnableClientScript = true; _maskEditValidator.IsValidEmpty = false; _maskEditValidator.Text = "*"; _maskEditValidator.EmptyValueBlurredText = "*"; _compareValidator = new CompareValidator(); _compareValidator.Visible = false; _compareValidator.ValueToCompare = "01/01/1900"; _compareValidator.Display = ValidatorDisplay.Dynamic; _compareValidator.Type = ValidationDataType.Date; _compareValidator.EnableClientScript = true; _compareValidator.Text = "*"; this.Controls.Add(_textBox); this.Controls.Add(_maskEditExtender); this.Controls.Add(_maskEditValidator); this.Controls.Add(_compareValidator); }
protected void ontext2(object sender, EventArgs e) { for (int i = 0; i < GridView1.Rows.Count; i++) { System.Web.UI.WebControls.CompareValidator cv = (System.Web.UI.WebControls.CompareValidator)GridView1.Rows[i].FindControl("CompareValidator8"); cv.ValueToCompare = TextBox6.Text; } GridView1.Focus(); }
protected void ontext1(object sender, EventArgs e) { for (int i = 0; i < GridView1.Rows.Count; i++) { System.Web.UI.WebControls.CompareValidator cv = (System.Web.UI.WebControls.CompareValidator)GridView1.Rows[i].FindControl("CompareValidator9"); cv.ValueToCompare = TextBox5.Text; // MessageBox.Show(cv.ValueToCompare); } TextBox6.Focus(); }
public BoundIntBox() { ib1 = new IntBox(); ib1.Width = Unit.Pixel(90); lbl1 = new Label(); lbl1.Text = "��ʼ"; ib2 = new IntBox(); ib2.Width = Unit.Pixel(90); lbl2 = new Label(); lbl2.Text = "����"; cv = new CompareValidator(); this.ValidatorColor = System.Drawing.Color.Red; }
private static CompareValidator GetDateValidator(Control controlToValidate) { CompareValidator validator = new CompareValidator(); validator.ID = controlToValidate.ID + "DateValidator"; validator.ErrorMessage = "<br/>" + Resources.ScrudResource.InvalidDate; validator.CssClass = "form-error"; validator.ControlToValidate = controlToValidate.ID; validator.EnableClientScript = true; validator.SetFocusOnError = true; validator.Display = ValidatorDisplay.Dynamic; validator.Type = ValidationDataType.Date; validator.Operator = ValidationCompareOperator.GreaterThan; validator.ValueToCompare = "1-1-1900"; return validator; }
protected override WebControls.BaseValidator CreateWebValidator() { WebControls.CompareValidator webValidator = new WebControls.CompareValidator(); this.AssociateControl(webValidator); webValidator.Operator = this.GetOperator(); webValidator.Type = this.GetValidationDataType(); if (webValidator.Type == WebControls.ValidationDataType.Date) { DateTime dateValue = Convert.ToDateTime(this.Validator.ValueToCompare); webValidator.ValueToCompare = dateValue.ToString("MM/dd/yyyy"); } else { webValidator.ValueToCompare = this.Validator.ValueToCompare.ToString(); } return(webValidator); }
public static BaseValidator[] GetValidators(EntityFieldDef field, string validationGroup) { List <BaseValidator> validators = new List <BaseValidator>(); switch (field.DataType) { case DataTypes.DateTime: { CompareValidator validator = new System.Web.UI.WebControls.CompareValidator(); validator.Operator = ValidationCompareOperator.DataTypeCheck; validator.Display = ValidatorDisplay.Dynamic; validator.Type = ValidationDataType.Date; validator.ErrorMessage = Resources.GlobalResources.InvalidFormat; validator.ValidationGroup = validationGroup; validators.Add(validator); } break; case DataTypes.Int: { CompareValidator validator = new System.Web.UI.WebControls.CompareValidator(); validator.Operator = ValidationCompareOperator.DataTypeCheck; validator.Display = ValidatorDisplay.Dynamic; validator.Type = ValidationDataType.Integer; validator.ErrorMessage = Resources.GlobalResources.InvalidFormat; validator.ValidationGroup = validationGroup; validators.Add(validator); } break; case DataTypes.Decimal: { CompareValidator validator = new System.Web.UI.WebControls.CompareValidator(); validator.Operator = ValidationCompareOperator.DataTypeCheck; validator.Display = ValidatorDisplay.Dynamic; validator.Type = ValidationDataType.Double; validator.ErrorMessage = Resources.GlobalResources.InvalidFormat; validator.ValidationGroup = validationGroup; validators.Add(validator); } break; } return(validators.ToArray()); }
protected override void CreateChildControls() { this.Controls.Clear(); this.textBox = new TextBox(); this.textBox.ID = this.ID; this.compareValidator = new CompareValidator(); this.compareValidator.Display = ValidatorDisplay.Dynamic; this.compareValidator.ID = this.ID + "CompareValidator"; this.compareValidator.ControlToValidate = this.ID; this.compareValidator.ValueToCompare = "1/1/1900"; this.compareValidator.Type = ValidationDataType.Date; this.compareValidator.ErrorMessage = CommonResource.InvalidDate; this.compareValidator.EnableClientScript = true; this.compareValidator.CssClass = this.ValidatorCssClass; this.requiredValidator = new RequiredFieldValidator(); this.requiredValidator.Display = ValidatorDisplay.Dynamic; this.requiredValidator.ID = this.ID + "RequiredFieldValidator"; this.requiredValidator.ControlToValidate = this.ID; this.requiredValidator.ErrorMessage = CommonResource.RequiredField; this.requiredValidator.EnableClientScript = true; this.requiredValidator.CssClass = this.ValidatorCssClass; this.Controls.Add(this.textBox); if (this.EnableValidation) { this.Controls.Add(this.compareValidator); } if (this.Required) { this.Controls.Add(this.requiredValidator); } this.AddjQueryUiDatePicker(); }
/// <include file='doc\CompareValidator.uex' path='docs/doc[@for="CompareValidator.CreateWebValidator"]/*' /> protected override WebCntrls.BaseValidator CreateWebValidator() { _webCompareValidator = new WebCntrls.CompareValidator(); return(_webCompareValidator); }
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); }
/// <summary> /// LSTs the custom fields item data bound. /// </summary> /// <param name="s">The s.</param> /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataListItemEventArgs"/> instance containing the event data.</param> void lstCustomFieldsItemDataBound(object s, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { CustomField currentField = (CustomField)e.Item.DataItem; PlaceHolder ph = (PlaceHolder)e.Item.FindControl("PlaceHolder"); switch (currentField.FieldType) { case Common.CustomFieldType.DropDownList: DropDownList ddl = new DropDownList(); ddl.ID = FIELD_VALUE_NAME; ddl.DataSource = CustomFieldSelectionManager.GetByCustomFieldId(currentField.Id); ddl.DataTextField = "Name"; ddl.DataValueField = "Value"; ddl.DataBind(); ddl.Items.Insert(0,new ListItem( "-- Select One --", string.Empty)); ddl.SelectedValue = currentField.Value; ph.Controls.Add(ddl); if (IsLocked) ddl.Enabled = false; break; case Common.CustomFieldType.Date: TextBox FieldValue1 = new TextBox(); AjaxControlToolkit.CalendarExtender cal = new AjaxControlToolkit.CalendarExtender(); Image img = new Image(); img.ID = "calImage"; img.CssClass = "icon"; img.ImageUrl = "~/images/calendar.gif"; cal.PopupButtonID = "calImage"; cal.TargetControlID = FIELD_VALUE_NAME; cal.ID = "Calendar1"; FieldValue1.ID = "FieldValue"; FieldValue1.Width = 80; ph.Controls.Add(FieldValue1); ph.Controls.Add(img); ph.Controls.Add(new LiteralControl(" ")); FieldValue1.Text = currentField.Value; ph.Controls.Add(cal); if (IsLocked) { cal.Enabled = false; FieldValue1.Enabled = false; img.Visible = false; } break; case Common.CustomFieldType.Text: var fieldValue = new TextBox {ID = FIELD_VALUE_NAME, Text = currentField.Value}; ph.Controls.Add(fieldValue); if (IsLocked) fieldValue.Enabled = false; break; case Common.CustomFieldType.YesNo: var chk = new CheckBox {ID = FIELD_VALUE_NAME}; if (!String.IsNullOrEmpty(currentField.Value)) chk.Checked = Boolean.Parse(currentField.Value); ph.Controls.Add(chk); if (IsLocked) chk.Enabled = false; break; case Common.CustomFieldType.RichText: var editor = new HtmlEditor {ID = FIELD_VALUE_NAME}; ph.Controls.Add(editor); editor.Text = currentField.Value; //if (IsLocked) // editor.Enabled = false; break; case Common.CustomFieldType.UserList: ddl = new DropDownList { ID = FIELD_VALUE_NAME, DataSource = UserManager.GetUsersByProjectId(currentField.ProjectId), DataTextField = "DisplayName", DataValueField = "UserName" }; ddl.DataBind(); ddl.Items.Insert(0, new ListItem("-- Select One --", string.Empty)); ddl.SelectedValue = currentField.Value; ph.Controls.Add(ddl); if (IsLocked) ddl.Enabled = false; break; } var lblFieldName = (Label)e.Item.FindControl("lblFieldName"); lblFieldName.AssociatedControlID = FIELD_VALUE_NAME; lblFieldName.Text = string.Format("{0}:", currentField.Name); if (EnableValidation) { //if required dynamically add a required field validator if (currentField.Required && currentField.FieldType != Common.CustomFieldType.YesNo) { var valReq = new RequiredFieldValidator { ControlToValidate = FIELD_VALUE_NAME, Text = " (required)", Display = ValidatorDisplay.Dynamic }; if (currentField.FieldType == Common.CustomFieldType.DropDownList) valReq.InitialValue = string.Empty; ph.Controls.Add(valReq); } //create datatype check validator if (currentField.FieldType != Common.CustomFieldType.YesNo) { var valCompare = new CompareValidator { Type = currentField.DataType, Text = String.Format("({0})", currentField.DataType), Operator = ValidationCompareOperator.DataTypeCheck, Display = ValidatorDisplay.Dynamic, ControlToValidate = FIELD_VALUE_NAME }; ph.Controls.Add(valCompare); } } } }
public void CultureInvariantValues_1 () { Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US", false); // Current date format --> "dmy" Page p = new Page (); CompareValidator v = new CompareValidator (); v.ControlToValidate = "tb1"; v.Type = ValidationDataType.Date; v.ValueToCompare = "2005/12/24"; v.CultureInvariantValues = true; TextBox tb1 = new TextBox (); tb1.ID = "tb1"; tb1.Text = "12.24.2005"; p.Controls.Add (tb1); p.Controls.Add (v); v.Validate (); Assert.AreEqual (true, v.IsValid, "CultureInvariantValues#1"); tb1.Text = "12/24/2005"; v.Validate (); Assert.AreEqual (true, v.IsValid, "CultureInvariantValues#2"); tb1.Text = "2005.12.24"; v.Validate (); Assert.AreEqual (true, v.IsValid, "CultureInvariantValues#3"); tb1.Text = "2005.24.12"; v.Validate (); Assert.AreEqual (false, v.IsValid, "CultureInvariantValues#4"); }
public void AddPassword(string name, string label, int span, int width, int length, bool optional, string warning) { this.AddEditLabel(label, span); TextBox textBox = new TextBox(); textBox.ID = name; textBox.Columns = width; textBox.MaxLength = length; textBox.TextMode = TextBoxMode.Password; this.editView.Controls.Add(textBox); if (!optional) { textBox.CssClass = this.editView.CssRequired; this.editView.Controls.Add(new LiteralControl("\r\n\t")); this.AddRequired(name, warning); } this.editView.Controls.Add(new LiteralControl("<br />\r\n\t")); TextBox textBox2 = new TextBox(); textBox2.ID = name + "_Repeat"; textBox2.Columns = width; textBox2.MaxLength = length; textBox2.TextMode = TextBoxMode.Password; this.editView.Controls.Add(textBox2); if (!optional) { textBox2.CssClass = this.editView.CssRequired; } this.editView.Controls.Add(new LiteralControl("\r\n\t")); CompareValidator compare = new CompareValidator(); compare.ID = name + "_Compare"; compare.ControlToValidate = name; compare.ControlToCompare = name + "_Repeat"; compare.ValidationGroup = this.editView.ID; compare.Text = "*"; compare.ErrorMessage = warning; compare.CssClass = this.editView.CssWarning; this.editView.Controls.Add(compare); this.EndCurrent(span); if (this.editView.focusControl == null) this.editView.focusControl = textBox; }
private void AddMinDateValidator() { this.compareValidator = new CompareValidator(); this.compareValidator.Display = ValidatorDisplay.Static; this.compareValidator.ID = this.ID + "CompareValidator"; this.compareValidator.ControlToValidate = this.ID; this.compareValidator.Type = ValidationDataType.Date; this.compareValidator.Operator = ValidationCompareOperator.GreaterThan; this.compareValidator.EnableClientScript = true; this.compareValidator.CssClass = this.ValidatorCssClass; this.compareValidator.SetFocusOnError = true; if (this.MinDate != null) { this.compareValidator.ValueToCompare = this.MinDate.ToString(); this.compareValidator.ErrorMessage = string.Format(CultureManager.GetCurrent(), CommonResource.DateMustBeGreaterThan, this.MinDate); } else { this.compareValidator.ValueToCompare = "1/1/1900"; this.compareValidator.ErrorMessage = CommonResource.InvalidDate; } }
//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); }
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); }
static public void WriteCompareValidator(HtmlTextWriter writer, CompareValidator cv, string className, string controlToValidate, string msg, string controlToCompare) { if (cv != null) { cv.CssClass = className; cv.ControlToValidate = controlToValidate; cv.ErrorMessage = msg; cv.ControlToCompare = controlToCompare; cv.RenderControl(writer); } }
/// <summary> /// Performs layout of the control. /// </summary> protected override void CreateChildControls() { // ----------------------------------------------- // | | ---------------------- | // | Username:* | | | | // | | ---------------------- | // ----------------------------------------------- // | | ---------------------- | // | Old Password:* | | | | // | | ---------------------- | // ----------------------------------------------- // | | ---------------------- | // | New Password:* | | | | // | | ---------------------- | // ----------------------------------------------- // | | ---------------------- | // | Confirm Password:* | | | | // | | ---------------------- | // ----------------------------------------------- // | | -------------- | // | | | Submit | | // | | -------------- | // ----------------------------------------------- // Layout the control. Table container = ControlContainer.NewTable(5, 2); // Row #1 m_usernameTextBox = new TextBox(); m_usernameTextBox.ID = "UsernameTextBox"; m_usernameTextBox.Width = Unit.Parse("150px"); RequiredFieldValidator usernameValidator = new RequiredFieldValidator(); usernameValidator.Display = ValidatorDisplay.None; usernameValidator.ErrorMessage = "Username is required."; usernameValidator.ControlToValidate = m_usernameTextBox.ID; container.Rows[0].Cells[0].Text = "Username:* "; container.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Right; container.Rows[0].Cells[1].Controls.Add(m_usernameTextBox); container.Rows[0].Cells[1].Controls.Add(usernameValidator); // Row #2 m_oldPasswordTextBox = new TextBox(); m_oldPasswordTextBox.ID = "OldPasswordTextBox"; m_oldPasswordTextBox.Width = Unit.Parse("150px"); m_oldPasswordTextBox.TextMode = TextBoxMode.Password; RequiredFieldValidator oldPasswordValidator = new RequiredFieldValidator(); oldPasswordValidator.Display = ValidatorDisplay.None; oldPasswordValidator.ErrorMessage = "Old Password is required."; oldPasswordValidator.ControlToValidate = m_oldPasswordTextBox.ID; container.Rows[1].Cells[0].Text = "Old Password:* "; container.Rows[1].Cells[0].HorizontalAlign = HorizontalAlign.Right; container.Rows[1].Cells[1].Controls.Add(m_oldPasswordTextBox); container.Rows[1].Cells[1].Controls.Add(oldPasswordValidator); // Row #3 m_newPasswordTextBox = new TextBox(); m_newPasswordTextBox.ID = "NewPasswordTextBox"; m_newPasswordTextBox.Width = Unit.Parse("150px"); m_newPasswordTextBox.TextMode = TextBoxMode.Password; RequiredFieldValidator newPasswordValidator = new RequiredFieldValidator(); newPasswordValidator.Display = ValidatorDisplay.None; newPasswordValidator.ErrorMessage = "New Password is required."; newPasswordValidator.ControlToValidate = m_newPasswordTextBox.ID; container.Rows[2].Cells[0].Text = "New Password:* "; container.Rows[2].Cells[0].HorizontalAlign = HorizontalAlign.Right; container.Rows[2].Cells[1].Controls.Add(m_newPasswordTextBox); container.Rows[2].Cells[1].Controls.Add(newPasswordValidator); // Row #4 m_confirmPasswordTextBox = new TextBox(); m_confirmPasswordTextBox.ID = "ConfirmPasswordTextBox"; m_confirmPasswordTextBox.Width = Unit.Parse("150px"); m_confirmPasswordTextBox.TextMode = TextBoxMode.Password; RequiredFieldValidator confirmPasswordValidator = new RequiredFieldValidator(); confirmPasswordValidator.Display = ValidatorDisplay.None; confirmPasswordValidator.ErrorMessage = "Confirm Password is required."; confirmPasswordValidator.ControlToValidate = m_confirmPasswordTextBox.ID; container.Rows[3].Cells[0].Text = "Confirm Password:* "; container.Rows[3].Cells[0].HorizontalAlign = HorizontalAlign.Right; container.Rows[3].Cells[1].Controls.Add(m_confirmPasswordTextBox); container.Rows[3].Cells[1].Controls.Add(confirmPasswordValidator); // Row #5 Button submitButton = new Button(); submitButton.Text = "Submit"; submitButton.Click += new System.EventHandler(SubmitButton_Click); CompareValidator passwordCompareValidator = new CompareValidator(); passwordCompareValidator.Display = ValidatorDisplay.None; passwordCompareValidator.ErrorMessage = "New Password and Confirm Password must match."; passwordCompareValidator.ControlToValidate = m_newPasswordTextBox.ID; passwordCompareValidator.ControlToCompare = m_confirmPasswordTextBox.ID; ValidationSummary validationSummary = new ValidationSummary(); validationSummary.ShowSummary = false; validationSummary.ShowMessageBox = true; container.Rows[4].Cells[0].Controls.Add(passwordCompareValidator); container.Rows[4].Cells[0].Controls.Add(validationSummary); container.Rows[4].Cells[1].HorizontalAlign = HorizontalAlign.Right; container.Rows[4].Cells[1].Controls.Add(submitButton); this.Controls.Clear(); this.Controls.Add(container); // Setup client-side scripts. Page.SetFocus(m_usernameTextBox); System.Text.StringBuilder with_1 = new StringBuilder(); with_1.Append("if (typeof(Page_ClientValidate) == \'function\') {"); with_1.Append("if (Page_ClientValidate() == false) { return false; }}"); with_1.Append("this.disabled = true;"); with_1.AppendFormat("document.all.{0}.disabled = true;", submitButton.ClientID); with_1.AppendFormat("{0};", Page.ClientScript.GetPostBackEventReference(submitButton, null)); submitButton.OnClientClick = with_1.ToString(); if (m_securityProvider.AuthenticationMode == AuthenticationMode.RSA) { // In RSA authentication mode the following substitution must take place: // Old Password -> Token // New Password -> New Pin // Confirm Password -> Confirm Pin oldPasswordValidator.ErrorMessage = "Token is required."; newPasswordValidator.ErrorMessage = "New Pin is required."; confirmPasswordValidator.ErrorMessage = "Confirm Pin is required."; passwordCompareValidator.ErrorMessage = "New Pin and Confirm Pin must match."; container.Rows[1].Cells[0].Text = "Token:*"; container.Rows[2].Cells[0].Text = "New Pin:*"; container.Rows[3].Cells[0].Text = "Confirm Pin:*"; if (Page.Session[Login.NewPinVerify] != null) { // It is verified that the user account is in "new pin" mode and user must create a new pin. System.Text.StringBuilder with_2 = new StringBuilder(); with_2.Append("Note: You are required to create a new pin for your RSA SecurID key. The pin must "); with_2.Append("be a 4 to 8 character alpha-numeric string. Please wait for the token on your RSA "); with_2.Append("SecurID key to change before proceeding."); m_container.UpdateMessageText(with_2.ToString(), MessageType.Information); } else { // User clicked on the Change Password link, so cannot allow a new pin to be created. this.Enabled = false; System.Text.StringBuilder with_3 = new StringBuilder(); with_3.Append("This screen is only active as part of an automated process. To create a new pin, "); with_3.Append("you must call the Operations Duty Specialist at 423-751-1700."); m_container.UpdateMessageText(with_3.ToString(), MessageType.Error); } } }
protected virtual IValidator AddCompareValidator(Control container, Control editor) { CompareValidator cmv = new CompareValidator { ID = "cmv" + Name, ControlToValidate = editor.ID, Display = ValidatorDisplay.Dynamic, Text = DataTypeText, ErrorMessage = DataTypeErrorMessage, Type = GetValidationDataType(), Operator = ValidationCompareOperator.DataTypeCheck }; container.Controls.Add(cmv); return cmv; }
/// <include file='doc\CompareValidator.uex' path='docs/doc[@for="CompareValidator.CreateWebValidator"]/*' /> protected override WebCntrls.BaseValidator CreateWebValidator() { _webCompareValidator = new WebCntrls.CompareValidator(); return _webCompareValidator; }
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); }
protected void rptCustomFields_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) return; var currentField = (UserCustomField)e.Item.DataItem; var ph = (PlaceHolder)e.Item.FindControl("PlaceHolder"); var id = (HiddenField)e.Item.FindControl("Id"); var name = (HiddenField)e.Item.FindControl("Name"); id.Value = currentField.Id.ToString(); name.Value = currentField.Name; switch (currentField.FieldType) { case CustomFieldType.DropDownList: var ddl = new DropDownList { ID = FIELD_VALUE_NAME, DataSource = UserCustomFieldSelectionManager.GetByCustomFieldId(currentField.Id), DataTextField = "Name", DataValueField = "Value", CssClass = "form-control" }; ddl.DataBind(); ddl.Items.Insert(0, new ListItem("-- Select One --", string.Empty)); ddl.SelectedValue = currentField.Value; ph.Controls.Add(ddl); if (IsLocked) { ddl.Enabled = false; } break; case CustomFieldType.Date: var fieldValue1 = new TextBox(); fieldValue1.Attributes.Add("bn-data-type", "date"); var cal = new CalendarExtender(); var img = new Image { ID = "calImage", CssClass = "icon", ImageUrl = "~/images/calendar.gif" }; cal.PopupButtonID = "calImage"; cal.TargetControlID = FIELD_VALUE_NAME; cal.ID = "Calendar1"; fieldValue1.ID = "FieldValue"; fieldValue1.Width = 80; ph.Controls.Add(fieldValue1); ph.Controls.Add(img); ph.Controls.Add(new LiteralControl(" ")); DateTime dt; var dateTimeValue = currentField.Value; if (DateTime.TryParse(dateTimeValue, out dt)) { dateTimeValue = dt.ToShortDateString(); } fieldValue1.Text = dateTimeValue; ph.Controls.Add(cal); if (IsLocked) { cal.Enabled = false; fieldValue1.Enabled = false; img.Visible = false; } break; case CustomFieldType.Text: var fieldValue = new TextBox { ID = FIELD_VALUE_NAME, Text = currentField.Value, CssClass = "form-control" }; fieldValue.Attributes.Add("bn-data-type", "text"); ph.Controls.Add(fieldValue); if (currentField.Value.Trim().ToLower().StartsWith("http")) { var url = new HyperLink { Target = "_blank", NavigateUrl = currentField.Value, Text = " GOTO >>" }; ph.Controls.Add(url); } if (IsLocked) { fieldValue.Enabled = false; } break; case CustomFieldType.YesNo: var chk = new CheckBox { ID = FIELD_VALUE_NAME }; if (!String.IsNullOrEmpty(currentField.Value)) { chk.Checked = Boolean.Parse(currentField.Value); } ph.Controls.Add(new LiteralControl("<div class=\"checkbox\">")); ph.Controls.Add(chk); ph.Controls.Add(new LiteralControl("</div>")); if (IsLocked) { chk.Enabled = false; } break; case CustomFieldType.RichText: var editor = new HtmlEditor { ID = FIELD_VALUE_NAME }; editor.Attributes.Add("bn-data-type", "html"); ph.Controls.Add(editor); editor.Text = currentField.Value; break; case CustomFieldType.UserList: ddl = new DropDownList { ID = FIELD_VALUE_NAME, DataSource = UserManager.GetAllUsers(), DataTextField = "DisplayName", DataValueField = "UserName", CssClass = "form-control" }; ddl.DataBind(); ddl.Items.Insert(0, new ListItem(GetGlobalResourceObject("SharedResources", "DropDown_SelectOne").ToString(), string.Empty)); ddl.SelectedValue = currentField.Value; ph.Controls.Add(ddl); if (IsLocked) { ddl.Enabled = false; } break; } var lblFieldName = (Label)e.Item.FindControl("lblFieldName"); lblFieldName.AssociatedControlID = FIELD_VALUE_NAME; lblFieldName.Text = currentField.Name; if (EnableValidation) { //if required dynamically add a required field validator if (currentField.Required && currentField.FieldType != CustomFieldType.YesNo) { var valReq = new RequiredFieldValidator { ControlToValidate = FIELD_VALUE_NAME, Text = string.Format(" ({0})", GetGlobalResourceObject("SharedResources", "Required")).ToLower(), Display = ValidatorDisplay.Dynamic, CssClass = "text-danger validation-error", SetFocusOnError = true }; if (currentField.FieldType == CustomFieldType.DropDownList) valReq.InitialValue = string.Empty; ph.Controls.Add(valReq); } //create data type check validator if (currentField.FieldType != CustomFieldType.YesNo) { var valCompare = new CompareValidator { Type = currentField.DataType, Text = String.Format("({0})", currentField.DataType), Operator = ValidationCompareOperator.DataTypeCheck, Display = ValidatorDisplay.Dynamic, ControlToValidate = FIELD_VALUE_NAME }; ph.Controls.Add(valCompare); } } }
/// <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 = " *"; 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; }
// 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); }
/// <summary> /// Init the components of the panel through the special pageid /// </summary> private void InitComponents() { Hashtable _htDataObjectdControlsInfo = new Hashtable(); 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); HtmlTableRow T_tr_title = new HtmlTableRow(); HtmlTableCell T_tc_title = new HtmlTableCell(); T_tr_title.Cells.Add(T_tc_title); T_Content.Rows.Add(T_tr_title); #region The title of the panel HtmlTable tb_title = new HtmlTable(); T_tc_title.Controls.Add(tb_title); tb_title.CellPadding = 0; tb_title.CellSpacing = 0; tb_title.Width = "100%"; tb_title.Height = "30px"; tb_title.Border = 0; tb_title.Attributes["class"] = "h3Row"; HtmlTableRow tr_title = new HtmlTableRow(); HtmlTableCell tc_title = new HtmlTableCell(); tr_title.Cells.Add(tc_title); tb_title.Rows.Add(tr_title); tc_title.InnerHtml = "<h3>工作流提交的数据字段内容</h3>"; #endregion #region The content of the panel HtmlTableRow T_tr_panelcontent = new HtmlTableRow(); T_tr_panelcontent.ID = "T_tr_panelcontent"; HtmlTableCell T_tc_panelcontent = new HtmlTableCell(); T_tr_panelcontent.Cells.Add(T_tc_panelcontent); T_Content.Rows.Add(T_tr_panelcontent); HtmlTable tb_panel_content = new HtmlTable(); tb_panel_content.Width = "100%"; tb_panel_content.Attributes["class"] = "tabForm"; T_tc_panelcontent.Controls.Add(tb_panel_content); IList<EWF_Flow_DataObject> _dataobjects = new EWF_Flow_AppBLL(App).GetDataObjectList(); int i = 0; foreach (EWF_Flow_DataObject _dataobject in _dataobjects) { if (_dataobject.Visible == "N") continue; #region 判断该控件是否已存在 if (_htDataObjectdControlsInfo.Contains(_dataobject.Name)) 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"] = "dataLabel"; tc_displayname.Attributes["Style"] = "width: 80px; height: 18px;"; tc_displayname.Attributes["nowrap"] = "nowrap"; tc_displayname.InnerText = _dataobject.DisplayName; tr_panel_detail.Cells.Add(tc_displayname); #endregion #region 增加Field Cell HtmlTableCell tc_control = new HtmlTableCell(); tc_control.Attributes["Class"] = "dataField"; if (_dataobject.ColSpan > 0) { if (i + _dataobject.ColSpan <= FieldCount) { tc_control.ColSpan = 2 * _dataobject.ColSpan - 1; i = i + _dataobject.ColSpan; } else { tc_control.ColSpan = 2 * (FieldCount - i) - 1; i = 0; } } else { i++; } WebControl control = null; int RelationType = _dataobject.RelationType; string RelationTableName = _dataobject.RelationTableName; string RelationValueField = _dataobject.RelationValueField; string RelationTextField = _dataobject.RelationTextField; #region 根据控件类型生成相应的控件 switch (_dataobject.ControlType) { case 1://Label control = new Label(); break; case 2://TextBox control = new TextBox(); if (_dataobject.DataType == 4) { control.Attributes["onfocus"] = "setday(this);"; } 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(); ((DropDownList)control).Items.Insert(0, new ListItem("请选择...", "0")); 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 (_dataobject.ControlHeight > 0) ((TextBox)control).Height = new Unit(_dataobject.ControlHeight); break; case 6://TextBox supports search control = new MCSSelectControl(); control.ID = "C_" + _dataobject.Name.ToString(); if (RelationType == 2)//Relation to the model table { ((MCSSelectControl)control).PageUrl = _dataobject.SearchPageURL; } break; case 7://MCSTreeControl control = new MCSTreeControl(); if (RelationType == 2)//Relation to the model table { control.ID = "C_" + _dataobject.Name.ToString(); //在设置控件DataSource之前,必须要有ID属性 Shen Gang 20090110 if (_dataobject.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity") { #region 如果为管理片区字段,则取员工所能管辖的片区 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(); } #endregion } else { ((MCSTreeControl)control).TableName = RelationTableName; ((MCSTreeControl)control).IDColumnName = RelationValueField; ((MCSTreeControl)control).NameColumnName = RelationTextField; ((MCSTreeControl)control).ParentColumnName = "SuperID"; } } break; } #endregion control.ID = "C_" + _dataobject.Name.ToString(); control.Enabled = _dataobject.Enable.ToUpper() == "Y"; control.ToolTip = _dataobject.Description; if (_dataobject.ControlWidth > 0) control.Width = _dataobject.ControlWidth; tc_control.Controls.Add(control); #region 如果是文本框时,加上输入验证控件 if (_dataobject.IsRequireField == "Y") { Label lbl_reqinfo = new Label(); lbl_reqinfo.Text = "*"; lbl_reqinfo.ForeColor = System.Drawing.Color.Red; tc_control.Controls.Add(lbl_reqinfo); } //add validate control for the textbox if (_dataobject.ControlType == 2 || _dataobject.ControlType == 5) { RequiredFieldValidator _requiredfieldvalidator = null; CompareValidator _comparevalidator = null; RegularExpressionValidator _regularexpressionvalidator = null; if (_dataobject.IsRequireField == "Y") { _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 (_dataobject.DataType == 1 || _dataobject.DataType == 2 || _dataobject.DataType == 4) //非varchar 字符串 { _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 (_dataobject.DataType == 1)//int { _comparevalidator.Type = ValidationDataType.Integer; _comparevalidator.ErrorMessage = "应为整数"; } if (_dataobject.DataType == 2)//decimal { _comparevalidator.Type = ValidationDataType.Double; _comparevalidator.ErrorMessage = "应为数字"; } if (_dataobject.DataType == 4)//datetime { _comparevalidator.Type = ValidationDataType.Date; _comparevalidator.ErrorMessage = "日期格式不正确"; } tc_control.Controls.Add(_comparevalidator); } else { if (_dataobject.RegularExpression != "") { _regularexpressionvalidator = new RegularExpressionValidator(); _regularexpressionvalidator.ControlToValidate = control.ID; _regularexpressionvalidator.ErrorMessage = "数据格式不正确"; _regularexpressionvalidator.ForeColor = System.Drawing.Color.Red; _regularexpressionvalidator.ValidationExpression = _dataobject.RegularExpression; _regularexpressionvalidator.ValidationGroup = ValidationGroup; _regularexpressionvalidator.Display = ValidatorDisplay.Dynamic; tc_control.Controls.Add(_regularexpressionvalidator); } } } #endregion tr_panel_detail.Cells.Add(tc_control); #endregion #region Record the info of the control created DataObjectControlInfo dataobjectcontrolinfo = new DataObjectControlInfo(); dataobjectcontrolinfo.ControlName = control.ID; dataobjectcontrolinfo.ControlType = _dataobject.ControlType; dataobjectcontrolinfo.DataObjectID = _dataobject.ID; dataobjectcontrolinfo.DataObjectName = _dataobject.Name; _htDataObjectdControlsInfo.Add(dataobjectcontrolinfo.DataObjectName, dataobjectcontrolinfo); #endregion } #endregion ViewState["HTDataObjectControlInfo"] = _htDataObjectdControlsInfo; if (new EWF_Flow_AppBLL(App).Model.RelateBusiness.ToUpper() == "Y") SetPanelEnable(false); }
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); }
public void CultureInvariantValues_Exception () { Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-GB", false); // Current date format --> "dmy" Page p = new Page (); CompareValidator v = new CompareValidator (); v.ControlToValidate = "tb1"; v.Type = ValidationDataType.Date; v.ValueToCompare = "12--24--2005"; v.CultureInvariantValues = false; TextBox tb1 = new TextBox (); tb1.ID = "tb1"; tb1.Text = "24.12.2005"; p.Controls.Add (tb1); p.Controls.Add (v); v.Validate (); Assert.AreEqual (true, v.IsValid, "CultureInvariantValues#1"); tb1.Text = "24-12-2005"; v.Validate (); }
private void AddMaxDateValidator() { if (this.MaxDate == null) { return; } this.maxDateCompareValidator = new CompareValidator(); this.maxDateCompareValidator.Display = ValidatorDisplay.Static; this.maxDateCompareValidator.ID = this.ID + "MaxDateCompareValidator"; this.maxDateCompareValidator.ControlToValidate = this.ID; this.maxDateCompareValidator.Type = ValidationDataType.Date; this.maxDateCompareValidator.Operator = ValidationCompareOperator.LessThan; this.maxDateCompareValidator.EnableClientScript = true; this.maxDateCompareValidator.CssClass = this.ValidatorCssClass; this.maxDateCompareValidator.SetFocusOnError = true; this.maxDateCompareValidator.ValueToCompare = this.MaxDate.ToString(); this.maxDateCompareValidator.ErrorMessage = string.Format(CultureManager.GetCurrent(), CommonResource.DateMustBeLessThan, this.MinDate); }
private void AddTextBoxValidator(webforms_sheetfielddef sfd ) { String FieldName=sfd.FieldName; String ErrorMessage=""; if(FieldName.ToLower()=="fname" || FieldName.ToLower()=="firstname") { ErrorMessage="First Name is a required field"; } else if(FieldName.ToLower()=="lname" || FieldName.ToLower()=="lastname") { ErrorMessage="Last Name is a required field"; } else if(FieldName.ToLower()=="birthdate" || FieldName.ToLower()=="bdate") { ErrorMessage="Birthdate is a required field"; } else if(sfd.IsRequired==(sbyte)1) { ErrorMessage="This is a required field"; } else { return; } // required field validator RequiredFieldValidator rv=new RequiredFieldValidator(); rv.ControlToValidate=""+sfd.WebSheetFieldDefID; rv.ErrorMessage=ErrorMessage; rv.Display=ValidatorDisplay.None; rv.SetFocusOnError=true; rv.ID="RequiredFieldValidator"+rv.ControlToValidate; Panel1.Controls.Add(rv); //callout extender AjaxControlToolkit.ValidatorCalloutExtender vc=new AjaxControlToolkit.ValidatorCalloutExtender(); vc.TargetControlID=rv.ID; vc.ID="ValidatorCalloutExtender"+rv.ID; Panel1.Controls.Add(vc); if(FieldName.ToLower()=="birthdate" || FieldName.ToLower()=="bdate") { //compare validator CompareValidator cv=new CompareValidator(); cv.ControlToValidate=""+sfd.WebSheetFieldDefID; cv.ErrorMessage="Invalid Date of Birth."; cv.Display=ValidatorDisplay.None; cv.Type=ValidationDataType.Date; cv.Operator=ValidationCompareOperator.DataTypeCheck; cv.SetFocusOnError=true; cv.ID="CompareValidator"+cv.ControlToValidate; //callout extender AjaxControlToolkit.ValidatorCalloutExtender vc1=new AjaxControlToolkit.ValidatorCalloutExtender(); vc1.TargetControlID=cv.ID; vc1.ID="ValidatorCalloutExtender"+cv.ID; Panel1.Controls.Add(cv); Panel1.Controls.Add(vc1); } }
public override void CreateChildControls() { // If user trying to visit settings screen, they must be logged on if (_userAction == "settings" && LoggedOnUserID == 0) RedirectToLoginPage(); // Alias text box _aliasTextBox = new TextBox(); _aliasTextBox.ID = "_aliasTextBox"; _aliasTextBox.Width = Unit.Pixel(150); _aliasTextBox.MaxLength = 100; _aliasTextBox.CssClass = "WebSolutionFormControl"; // Alias validator _aliasValidator = new ValidAlias(); _aliasValidator.ControlToValidate = "_aliasTextBox"; _aliasValidator.CssClass = "WebSolutionFormControl"; // Email entry row _emailTextBox = new TextBox(); _emailTextBox.ID = "_emailTextBox"; _emailTextBox.Width = Unit.Pixel(150); _emailTextBox.MaxLength = 100; _emailTextBox.CssClass = "WebSolutionFormControl"; // Email validator _emailValidator = new ValidEmail(); _emailValidator.ControlToValidate = "_emailTextBox"; _emailValidator.CssClass = "WebSolutionFormControl"; // CHANGED by Arthur Zaczek /** // Password entry row _passwordTextBox = new TextBox(); _passwordTextBox.ID = "_passwordTextBox"; _passwordTextBox.Width = Unit.Pixel(150); _passwordTextBox.MaxLength = 50; _passwordTextBox.TextMode = TextBoxMode.Password; _passwordTextBox.CssClass = "WebSolutionFormControl"; // Password validator _passwordValidator = new ValidPassword(); _passwordValidator.ControlToValidate = "_passwordTextBox"; _passwordValidator.CssClass = "WebSolutionFormControl"; // Password confirm entry row _confirmTextBox = new TextBox(); _confirmTextBox.ID = "_confirmTextBox"; _confirmTextBox.Width = Unit.Pixel(150); _confirmTextBox.MaxLength = 50; _confirmTextBox.TextMode = TextBoxMode.Password; _confirmTextBox.CssClass = "WebSolutionFormControl";*/ // Confirm validator _confirmValidator = new CompareValidator(); _confirmValidator.CssClass = "WebSolutionFormControl"; _confirmValidator.ControlToValidate = "_confirmTextBox"; _confirmValidator.ControlToCompare = "_passwordTextBox"; _confirmValidator.ErrorMessage = "Passwords must be identical."; _confirmValidator.Display = ValidatorDisplay.Dynamic; /* // Confirm required field validator _confirmRequiredValidator = new RequiredFieldValidator(); _confirmRequiredValidator.CssClass = "WebSolutionFormControl"; _confirmRequiredValidator.ControlToValidate = "_confirmTextBox"; _confirmRequiredValidator.ErrorMessage = "Please enter a password."; _confirmRequiredValidator.Display = ValidatorDisplay.Dynamic;*/ // Remember me check box _rememberMeCheckBox = new CheckBox(); _rememberMeCheckBox.Text = "Remember me"; _rememberMeCheckBox.CssClass = "WebSolutionFormControl"; // Submit button _submitButton = new Button(); _submitButton.Text = _userAction == "settings" ? "Save" : "Create Account"; _submitButton.Click += new System.EventHandler(SubmitButton_Click); _submitButton.CssClass = "WebSolutionFormControl"; // Avatar _inputFile = new HtmlInputFile(); _inputFile.ID = "_inputFile"; // Avatar validator _avatarValidator = new ValidAvatar(); _avatarValidator.ControlToValidate = "_inputFile"; _avatarValidator.InputFile = _inputFile; _avatarValidator.CssClass = "WebSolutionFormControl"; // Add child controls Controls.Add(_aliasTextBox); Controls.Add(_aliasValidator); Controls.Add(_emailTextBox); Controls.Add(_emailValidator); // Controls.Add(_passwordTextBox); // Controls.Add(_passwordValidator); // Controls.Add(_confirmTextBox); // Controls.Add(_confirmValidator); // Controls.Add(_confirmRequiredValidator); Controls.Add(_rememberMeCheckBox); Controls.Add(_submitButton); Controls.Add(_inputFile); Controls.Add(_avatarValidator); // Populate controls with user settings? if (_userAction == "settings") PopulateUserSettings(); }
public void InstantiateIn (Control container) { Table table = new Table (); table.CellPadding = 0; // Row #0 table.Controls.Add ( CreateRow (new LiteralControl (_owner.ChangePasswordTitleText), null, null, _owner.TitleTextStyle, null)); // Row #1 if (_owner.InstructionText.Length > 0) { table.Controls.Add ( CreateRow (new LiteralControl (_owner.InstructionText), null, null, _owner.InstructionTextStyle, null)); } // Row #2 if (_owner.DisplayUserName) { TextBox UserName = new TextBox (); UserName.ID = "UserName"; UserName.Text = _owner.UserName; UserName.ApplyStyle (_owner.TextBoxStyle); Label UserNameLabel = new Label (); UserNameLabel.ID = "UserNameLabel"; UserNameLabel.AssociatedControlID = "UserName"; UserNameLabel.Text = _owner.UserNameLabelText; RequiredFieldValidator UserNameRequired = new RequiredFieldValidator (); UserNameRequired.ID = "UserNameRequired"; UserNameRequired.ControlToValidate = "UserName"; UserNameRequired.ErrorMessage = _owner.UserNameRequiredErrorMessage; UserNameRequired.ToolTip = _owner.UserNameRequiredErrorMessage; UserNameRequired.Text = "*"; UserNameRequired.ValidationGroup = _owner.ID; UserNameRequired.ApplyStyle (_owner.ValidatorTextStyle); table.Controls.Add (CreateRow (UserNameLabel, UserName, UserNameRequired, _owner.LabelStyle, null)); } // Row #3 TextBox CurrentPassword = new TextBox (); CurrentPassword.ID = "CurrentPassword"; CurrentPassword.TextMode = TextBoxMode.Password; CurrentPassword.ApplyStyle (_owner.TextBoxStyle); Label CurrentPasswordLabel = new Label (); CurrentPasswordLabel.ID = "CurrentPasswordLabel"; CurrentPasswordLabel.AssociatedControlID = "CurrentPasswordLabel"; CurrentPasswordLabel.Text = _owner.PasswordLabelText; RequiredFieldValidator CurrentPasswordRequired = new RequiredFieldValidator (); CurrentPasswordRequired.ID = "CurrentPasswordRequired"; CurrentPasswordRequired.ControlToValidate = "CurrentPassword"; CurrentPasswordRequired.ErrorMessage = _owner.PasswordRequiredErrorMessage; CurrentPasswordRequired.ToolTip = _owner.PasswordRequiredErrorMessage; CurrentPasswordRequired.Text = "*"; CurrentPasswordRequired.ValidationGroup = _owner.ID; CurrentPasswordRequired.ApplyStyle (_owner.ValidatorTextStyle); table.Controls.Add (CreateRow (CurrentPasswordLabel, CurrentPassword, CurrentPasswordRequired, _owner.LabelStyle, null)); // Row #4 TextBox NewPassword = new TextBox (); NewPassword.ID = "NewPassword"; NewPassword.TextMode = TextBoxMode.Password; NewPassword.ApplyStyle (_owner.TextBoxStyle); Label NewPasswordLabel = new Label (); NewPasswordLabel.ID = "NewPasswordLabel"; NewPasswordLabel.AssociatedControlID = "NewPassword"; NewPasswordLabel.Text = _owner.NewPasswordLabelText; RequiredFieldValidator NewPasswordRequired = new RequiredFieldValidator (); NewPasswordRequired.ID = "NewPasswordRequired"; NewPasswordRequired.ControlToValidate = "NewPassword"; NewPasswordRequired.ErrorMessage = _owner.PasswordRequiredErrorMessage; NewPasswordRequired.ToolTip = _owner.PasswordRequiredErrorMessage; NewPasswordRequired.Text = "*"; NewPasswordRequired.ValidationGroup = _owner.ID; NewPasswordRequired.ApplyStyle (_owner.ValidatorTextStyle); table.Controls.Add (CreateRow (NewPasswordLabel, NewPassword, NewPasswordRequired, _owner.LabelStyle, null)); // Row #5 if (_owner.PasswordHintText.Length > 0) { table.Controls.Add ( CreateRow (new LiteralControl (""), new LiteralControl (_owner.PasswordHintText), new LiteralControl (""), null, _owner.PasswordHintStyle)); } // Row #6 TextBox ConfirmNewPassword = new TextBox (); ConfirmNewPassword.ID = "ConfirmNewPassword"; ConfirmNewPassword.TextMode = TextBoxMode.Password; ConfirmNewPassword.ApplyStyle (_owner.TextBoxStyle); Label ConfirmNewPasswordLabel = new Label (); ConfirmNewPasswordLabel.ID = "ConfirmNewPasswordLabel"; ConfirmNewPasswordLabel.AssociatedControlID = "ConfirmNewPasswordLabel"; ConfirmNewPasswordLabel.Text = _owner.ConfirmNewPasswordLabelText; RequiredFieldValidator ConfirmNewPasswordRequired = new RequiredFieldValidator (); ConfirmNewPasswordRequired.ID = "ConfirmNewPasswordRequired"; ConfirmNewPasswordRequired.ControlToValidate = "ConfirmNewPassword"; ConfirmNewPasswordRequired.ErrorMessage = _owner.PasswordRequiredErrorMessage; ConfirmNewPasswordRequired.ToolTip = _owner.PasswordRequiredErrorMessage; ConfirmNewPasswordRequired.Text = "*"; ConfirmNewPasswordRequired.ValidationGroup = _owner.ID; ConfirmNewPasswordRequired.ApplyStyle (_owner.ValidatorTextStyle); table.Controls.Add (CreateRow (ConfirmNewPasswordLabel, ConfirmNewPassword, ConfirmNewPasswordRequired, _owner.LabelStyle, null)); // Row #7 CompareValidator NewPasswordCompare = new CompareValidator (); NewPasswordCompare.ID = "NewPasswordCompare"; NewPasswordCompare.ControlToCompare = "NewPassword"; NewPasswordCompare.ControlToValidate = "ConfirmNewPassword"; NewPasswordCompare.Display = ValidatorDisplay.Dynamic; NewPasswordCompare.ErrorMessage = _owner.ConfirmPasswordCompareErrorMessage; NewPasswordCompare.ValidationGroup = _owner.ID; table.Controls.Add (CreateRow (NewPasswordCompare, null, null, null, null)); // Row #8 Literal FailureTextLiteral = new Literal (); FailureTextLiteral.ID = "FailureText"; FailureTextLiteral.EnableViewState = false; if (_owner.FailureTextStyle.ForeColor.IsEmpty) _owner.FailureTextStyle.ForeColor = System.Drawing.Color.Red; table.Controls.Add (CreateRow (FailureTextLiteral, null, null, _owner.FailureTextStyle, null)); // Row #9 WebControl ChangePasswordButton = null; switch (_owner.ChangePasswordButtonType) { case ButtonType.Button: ChangePasswordButton = new Button (); break; case ButtonType.Image: ChangePasswordButton = new ImageButton (); break; case ButtonType.Link: ChangePasswordButton = new LinkButton (); break; } ChangePasswordButton.ID = "ChangePasswordPushButton"; ChangePasswordButton.ApplyStyle (_owner.ChangePasswordButtonStyle); ((IButtonControl) ChangePasswordButton).CommandName = ChangePassword.ChangePasswordButtonCommandName; ((IButtonControl) ChangePasswordButton).Text = _owner.ChangePasswordButtonText; ((IButtonControl) ChangePasswordButton).ValidationGroup = _owner.ID; WebControl CancelButton = null; switch (_owner.CancelButtonType) { case ButtonType.Button: CancelButton = new Button (); break; case ButtonType.Image: CancelButton = new ImageButton (); break; case ButtonType.Link: CancelButton = new LinkButton (); break; } CancelButton.ID = "CancelPushButton"; CancelButton.ApplyStyle (_owner.CancelButtonStyle); ((IButtonControl) CancelButton).CommandName = ChangePassword.CancelButtonCommandName; ((IButtonControl) CancelButton).Text = _owner.CancelButtonText; ((IButtonControl) CancelButton).CausesValidation = false; table.Controls.Add (CreateRow (ChangePasswordButton, CancelButton, new LiteralControl (""), null, null)); // Row #10 TableRow linksRow = new TableRow (); TableCell linksCell = new TableCell (); linksCell.ColumnSpan = 2; linksCell.ControlStyle.CopyFrom (_owner.HyperLinkStyle); linksRow.Cells.Add (linksCell); if (AddLink (_owner.HelpPageUrl, _owner.HelpPageText, _owner.HelpPageIconUrl, linksCell)) linksCell.Controls.Add (new LiteralControl ("<br/>")); if (AddLink (_owner.CreateUserUrl, _owner.CreateUserText, _owner.CreateUserIconUrl, linksCell)) linksCell.Controls.Add (new LiteralControl ("<br/>")); if (AddLink (_owner.PasswordRecoveryUrl, _owner.PasswordRecoveryText, _owner.PasswordRecoveryIconUrl, linksCell)) linksCell.Controls.Add (new LiteralControl ("<br/>")); AddLink (_owner.EditProfileUrl, _owner.EditProfileText, _owner.EditProfileIconUrl, linksCell); table.Controls.Add (linksRow); container.Controls.Add (table); }