public RangeBox() { tb = new TextBox(); rangeValidator = new RangeValidator(); //�趨Ĭ��ֵ IsErrorTextBelow = true; IsRequired = false; ValidatorColor = System.Drawing.Color.Red; Type = ValidationDataType.Currency; MaxValue = "1000000"; MinValue = "0"; }
public static void SetDateRange(RangeValidator rv, DateTime from, DateTime to, bool setErrMsg, int? iindex) { rv.MinimumValue = from.ToShortDateString(); rv.MaximumValue = to.ToShortDateString(); rv.Type = ValidationDataType.Date; if (setErrMsg) { if (iindex != null) { rv.ErrorMessage = string.Format(rv.ErrorMessage, from.ToShortDateString(), to.ToShortDateString(), iindex.ToString()); } else { rv.ErrorMessage = string.Format(rv.ErrorMessage, from.ToShortDateString(), to.ToShortDateString()); } } }
//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); }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { base.CreateChildControls(); _rangeValidator = new RangeValidator(); _rangeValidator.ID = this.ID + "_RV"; _rangeValidator.ControlToValidate = this.ID; _rangeValidator.Display = ValidatorDisplay.Dynamic; _rangeValidator.CssClass = "validation-error help-inline"; _rangeValidator.Type = this.NumberType; _rangeValidator.MinimumValue = int.MinValue.ToString(); _rangeValidator.MaximumValue = int.MaxValue.ToString(); Controls.Add( _rangeValidator ); }
protected override WebCntrls.BaseValidator CreateWebValidator() { _webRangeValidator = new WebCntrls.RangeValidator(); return(_webRangeValidator); }
// 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); }
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); }
private void GetRTextBoxScore(RangeValidator rangeValidator, HyperLink comment, SqlCommand cmd, TextBox txtR) { using (SqlConnection conn = new SqlConnection(Shared.SqlConnString)) { conn.Open(); cmd.Connection = conn; using (cmd) { try { SqlDataReader reader = cmd.ExecuteReader(); using (reader) { if (reader.HasRows) { while (reader.Read()) { Session["UserDivID"] = reader["UserDivID"].ToString(); CriteriaID = int.Parse(reader["CriteriaID"].ToString()); } } else { txtR.Enabled = false; rangeValidator.Enabled = false; comment.Enabled = false; } } } catch (Exception ex) { Response.Write(ex.ToString()); } } } }
private void SetUpRangeValidator(RangeValidator validator, MetaColumn column) { // Nothing to do if no range was specified var rangeAttribute = column.Attributes.OfType<RangeAttribute>().FirstOrDefault(); if (rangeAttribute == null) return; // Make sure the attribute doesn't get validated a second time by the DynamicValidator IgnoreModelValidationAttribute(rangeAttribute.GetType()); validator.Enabled = true; Func<object, string> converter; switch (validator.Type) { case ValidationDataType.Integer: converter = val => Convert.ToInt32(val, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); break; case ValidationDataType.Double: converter = val => Convert.ToDouble(val, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); break; case ValidationDataType.String: default: converter = val => val.ToString(); break; } validator.MinimumValue = converter(rangeAttribute.Minimum); validator.MaximumValue = converter(rangeAttribute.Maximum); if (String.IsNullOrEmpty(validator.ErrorMessage)) { validator.ErrorMessage = HttpUtility.HtmlEncode(rangeAttribute.FormatErrorMessage(column.DisplayName)); } }
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); }
public void AddCurrencyBox(string name, string label, decimal? value, int span, int width, int length, decimal min, decimal max, string warning) { this.AddEditLabel(label, span); TextBox textBox = new TextBox(); textBox.ID = name; textBox.Text = (value.HasValue ? value.ToString() : string.Empty); textBox.Columns = width; textBox.MaxLength = length; textBox.CssClass = this.editView.CssRequired; this.editView.Controls.Add(textBox); this.editView.Controls.Add(new LiteralControl("\r\n\t")); this.AddRequired(name, warning); this.editView.Controls.Add(new LiteralControl("\r\n\t")); RangeValidator range = new RangeValidator(); range.ID = name + "_Range"; range.ControlToValidate = name; range.ValidationGroup = this.editView.ID; range.Type = ValidationDataType.Currency; range.MinimumValue = min.ToString(); range.MaximumValue = max.ToString(); range.Text = "*"; range.ErrorMessage = warning; range.CssClass = this.editView.CssWarning; this.editView.Controls.Add(range); this.EndCurrent(span); if (this.editView.focusControl == null) this.editView.focusControl = textBox; }
public void AddDatePicker(string name, string label, DateTime? value, int span, string format, DateTime min, DateTime max, string warning) { // TODO Picker string dateFormat = (!string.IsNullOrEmpty(format) ? format : "MM/dd/yyyy"); this.AddEditLabel(label, span); TextBox textBox = new TextBox(); textBox.ID = name; textBox.Text = (value.HasValue ? value.Value.ToString(dateFormat) : string.Empty); textBox.Columns = Math.Max(dateFormat.Length, 10); textBox.MaxLength = Math.Max(dateFormat.Length, 10); textBox.CssClass = this.editView.CssRequired; this.editView.Controls.Add(textBox); this.editView.Controls.Add(new LiteralControl("\r\n\t")); this.AddRequired(name, warning); this.editView.Controls.Add(new LiteralControl("\r\n\t")); RangeValidator range = new RangeValidator(); range.ID = name + "_Range"; range.ControlToValidate = name; range.ValidationGroup = this.editView.ID; range.Type = ValidationDataType.Date; range.MinimumValue = min.ToString(dateFormat); range.MaximumValue = max.ToString(dateFormat); range.Text = "*"; range.ErrorMessage = warning; range.CssClass = this.editView.CssWarning; this.editView.Controls.Add(range); this.EndCurrent(span); if (this.editView.focusControl == null) this.editView.focusControl = textBox; }
public static void SetDateRange(RangeValidator rv, DateTime from, DateTime to, bool setErrMsg) { SetDateRange(rv, from, to, setErrMsg, null); }
/// <summary> /// Create, initialize and return individual child controls /// </summary> /// <param name="controlType">Type of control to create</param> /// <returns>Created control</returns> protected virtual Control CreateChildControl(ContainedControlType controlType) { switch (controlType) { case ContainedControlType.EntryTextBox: TextBox textBox = new TextBox(); textBox.ID = _entryTextBoxId; textBox.EnableViewState = true; textBox.Visible = true; return textBox; case ContainedControlType.PatternValidator: RegularExpressionValidator patternValidator = new RegularExpressionValidator(); patternValidator.ID = _patternValidatorId; patternValidator.Text = ControlResources.Entry_Pattern_Text; patternValidator.EnableViewState = true; patternValidator.Visible = true; return patternValidator; case ContainedControlType.RangeValidator: RangeValidator rangeValidator = new RangeValidator(); rangeValidator.ID = _rangeValidatorId; rangeValidator.Text = ControlResources.Entry_Range_Text; rangeValidator.EnableViewState = true; rangeValidator.Visible = false; //NOTE: Defaults to inactive - activiated only if consuming code provides both a Min and Max value. return rangeValidator; case ContainedControlType.RequiredValidator: RequiredFieldValidator requiredValidator = new RequiredFieldValidator(); requiredValidator.ID = _requiredValidatorId; requiredValidator.Text = ControlResources.Entry_Required_Text; requiredValidator.EnableViewState = true; requiredValidator.Visible = false; //NOTE: Required=false is the default. Consuming code must explicitely set Required=true return requiredValidator; default: return null; } }
/// <include file='doc\RangeValidator.uex' path='docs/doc[@for="RangeValidator.CreateWebValidator"]/*' /> protected override WebCntrls.BaseValidator CreateWebValidator() { _webRangeValidator = new WebCntrls.RangeValidator(); return _webRangeValidator; }
/// <summary> /// Populates the R textboxes - TODO: Make the controls dynamic, not hardcoded (R1_1, R1_C)... /// </summary> /// <param name="conn"></param> /// <param name="rangeValidator"></param> /// <param name="comment"></param> /// <param name="txtRScore"></param> /// <param name="txtRComment"></param> private void PopulateRTextBox(RangeValidator rangeValidator, HyperLink comment, TextBox txtRScore, TextBox txtRComment) { SqlConnection conn = new SqlConnection(Shared.SqlConnString); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string SqlGetRQuery = "SELECT * FROM UserCriteria UC, UserDivID UDI " + "WHERE UC.UserDivID = UDI.UserDivID AND UDI.UserID = @UserID AND " + "UC.CriteriaID = @UCCriteriaID AND UC.CMID = @SelectedCMID AND UDI.DivID = @SelectedDivisionID "; SqlCommand getR = new SqlCommand(SqlGetRQuery, conn); getR.Parameters.AddWithValue("@UserID", int.Parse(Session["UserID"].ToString())); getR.Parameters.AddWithValue("@UCCriteriaID", CriteriaID); getR.Parameters.AddWithValue("@SelectedCMID", int.Parse(Session["SelectedCMID"].ToString())); getR.Parameters.AddWithValue("@SelectedDivisionID", int.Parse(Session["SelectedDivisionID"].ToString())); GetRTextBoxScore(RangeValidator1, Comment1, getR, R1_1); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string QueryGetRespID = "SELECT ResponsivenessID FROM dbo.[Responsiveness] WHERE UserDivID = @UserDivID AND ResponsivenessID = @ResponsivenessID"; SqlCommand getRespID = new SqlCommand(QueryGetRespID, conn); getRespID.Parameters.AddWithValue("@UserDivID", int.Parse(Session["UserDivID"].ToString())); getRespID.Parameters.AddWithValue("@ResponsivenessID", RespID); GetResponsivenessID(getRespID); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string QueryGetRecord = "SELECT R1_1 FROM dbo.[ResponsivenessScore] WHERE ResponsivenessID = @ResponsivenessID "; SqlCommand getRecord = new SqlCommand(QueryGetRecord, conn); getRecord.Parameters.AddWithValue("@ResponsivenessID", RespID); GetRecord(getRecord, R1_1, RespID); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string QueryGetCommentSql = "SELECT RC1_1 FROM dbo.[ResponsivenessComment] WHERE ResponsivenessID = @ResponsivenessID"; SqlCommand getComment = new SqlCommand(QueryGetCommentSql, conn); getComment.Parameters.AddWithValue("@ResponsivenessID", RespID); GetComment(getComment, R1_1C); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// }
/// <summary> /// Returns one settings row that contains a cell for help, a cell for setting item /// name and a cell for setting item and validators. /// </summary> /// <param name="currentSetting"> /// The current setting. /// </param> /// <param name="currentItem"> /// The current item. /// </param> /// <returns> /// A table row. /// </returns> private TableRow CreateOneSettingRow(string currentSetting, ISettingItem currentItem) { // the table row is going to have three cells var row = new TableRow(); // cell for help icon and description var helpCell = new TableCell(); Image img; if (currentItem.Description.Length > 0) { var myimg = ((Page)this.Page).CurrentTheme.GetImage("Buttons_Help", "Help.gif"); img = new Image { ImageUrl = myimg.ImageUrl, Height = myimg.Height, Width = myimg.Width, AlternateText = currentItem.Description }; // Jminond: added netscape tooltip support img.Attributes.Add("title", General.GetString(currentSetting + "_DESCRIPTION")); img.ToolTip = General.GetString(currentSetting + "_DESCRIPTION"); // Fixed key for simplicity } else { // Jes1111 - 17/12/2004 img = new Image { Width = Unit.Pixel(25), ImageUrl = ((Page)this.Page).CurrentTheme.GetImage("Spacer", "Spacer.gif").ImageUrl }; } helpCell.Controls.Add(img); // add help cell to the row row.Cells.Add(helpCell); // Setting Name cell var nameCell = new TableCell(); nameCell.Attributes.Add("width", "20%"); nameCell.CssClass = "SubHead"; nameCell.Text = currentItem.EnglishName.Length == 0 ? General.GetString(currentSetting, currentSetting + "<br />Key Not In Resources") : General.GetString(currentItem.EnglishName, currentItem.EnglishName); // add name cell to the row row.Cells.Add(nameCell); // Setting Control cell var settingCell = new TableCell(); settingCell.Attributes.Add("width", "80%"); settingCell.CssClass = "st-control"; StringBuilder script = new StringBuilder(); script.Append("<script language=\"javascript\" type=\"text/javascript\">"); //script.AppendFormat("$.extend($.ui.multiselect, { locale: { addAll: '{0}', removeAll: '{1}', itemsCount: '{2}' }});", "Agregar todo", "Remover todooooo", "items seleccionados"); script.Append("$.extend($.ui.multiselect, { locale: { addAll: '"); script.AppendFormat("{0}",General.GetString("ADD_ALL", "Add all", null)); script.Append("',removeAll: '"); script.AppendFormat("{0}", General.GetString("REMOVE_ALL", "Remove all", null)); script.Append("',itemsCount: '"); script.AppendFormat("{0}", General.GetString("ITEMS_SELECTED", "items selected", null)); script.Append("' }});$(function(){ $.localise('ui-multiselect', {path: 'aspnet_client/jQuery/'});"); script.Append("$(\".multiselect\").multiselect({sortable: false, searchable: false});}); </script>"); this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "jqueryMultiselect", script.ToString()); Control editControl; try { editControl = currentItem.EditControl; editControl.ID = currentSetting; // Jes1111 editControl.EnableViewState = true; } catch (Exception) { editControl = new LiteralControl("There was an error loading this control"); // LogHelper.Logger.Log(Appleseed.Framework.LogLevel.Warn, "There was an error loading '" + currentItem.EnglishName + "'", ex); } settingCell.Controls.Add(editControl); // TODO: WHAT IS THIS? // nameText.LabelForControl = editControl.ClientID; // Add control to edit controls collection this.EditControls.Add(currentSetting, editControl); // Validators settingCell.Controls.Add(new LiteralControl("<br />")); // Required // TODO : Whhn we bring back ELB easy list box, we need to put this back /* if (currentItem.Required && !(editControl is ELB.EasyListBox)) { RequiredFieldValidator req = new RequiredFieldValidator(); req.ErrorMessage =General.GetString("SETTING_REQUIRED", "%1% is required!", req).Replace("%1%", currentSetting); req.ControlToValidate = currentSetting; req.CssClass = "Error"; req.Display = ValidatorDisplay.Dynamic; req.EnableClientScript = true; settingCell.Controls.Add(req); } */ // Range Validator if (currentItem.MinValue != 0 || currentItem.MaxValue != 0) { var rang = new RangeValidator(); switch (currentItem.Value.GetType().Name.ToLowerInvariant()) { case "string": rang.Type = ValidationDataType.String; break; case "int": rang.Type = ValidationDataType.Integer; break; // case PropertiesDataType.Currency: // rang.Type = ValidationDataType.Currency; // break; case "datetime": rang.Type = ValidationDataType.Date; break; case "double": rang.Type = ValidationDataType.Double; break; } if (currentItem.MinValue >= 0 && currentItem.MaxValue >= currentItem.MinValue) { rang.MinimumValue = currentItem.MinValue.ToString(); if (currentItem.MaxValue == 0) { rang.ErrorMessage = General.GetString( "SETTING_EQUAL_OR_GREATER", "%1% must be equal or greater than %2%!", rang).Replace( "%1%", currentSetting).Replace("%2%", currentItem.MinValue.ToString()); } else { rang.MaximumValue = currentItem.MaxValue.ToString(); rang.ErrorMessage = General.GetString("SETTING_BETWEEN", "%1% must be between %2% and %3%!", rang).Replace( "%1%", currentSetting).Replace("%2%", currentItem.MinValue.ToString()).Replace( "%3%", currentItem.MaxValue.ToString()); } } rang.ControlToValidate = currentSetting; rang.CssClass = "Error"; rang.Display = ValidatorDisplay.Dynamic; rang.EnableClientScript = true; settingCell.Controls.Add(rang); } // add setting cell into the row row.Cells.Add(settingCell); // all done send it back return row; }
private Control CreateColumnControl( TableCell td, DataColumn _dc ) { TextBox txt = null; Label lbl = null; DropDownList ddl = null; RegularExpressionValidator rexpval = null; RangeValidator rangeVal = null; switch (_type) { case ListItemType.Item: // if datacolumn is readonly and unique then it is a primary key // render it as label a distinctive style lbl = CreateColumnAsLabel(td, _dc, lbl); break; case ListItemType.EditItem: _iEditTabOrder ++; if (_dc.ReadOnly ) { // check if this column should be created as DropDownList if (DropDownListColumns.Contains(_dc.ColumnName)) { ddl = CreateColumnAsDropDown(td, _dc, ddl); } else lbl = CreateColumnAsLabel(td, _dc, lbl); } else { switch (_dc.DataType.ToString()) { case "System.Boolean": RadioButtonList rbl = new RadioButtonList(); rbl.ID = "rbl" + _dc.ColumnName; Fields.Add(rbl.ID, _dc.ColumnName); ListItem li = new ListItem("Yes", "True"); rbl.Items.Add(li); li = new ListItem("No", "False"); rbl.Items.Add(li); rbl.RepeatLayout = RepeatLayout.Flow; rbl.RepeatDirection = RepeatDirection.Horizontal; rbl.DataBound += new EventHandler(rbl_DataBound); rbl.CssClass = CssClassEditControl; rbl.TabIndex = Convert.ToInt16( _iEditTabOrder * TabInterval ); td.Controls.Add(rbl); break; case "System.String": txt = new TextBox(); txt.ID = "txt" + _dc.ColumnName; Fields.Add(txt.ID, _dc.ColumnName); if (_dc.MaxLength <= 0) _dc.MaxLength = 50; txt.MaxLength = _dc.MaxLength; txt.Width = Unit.Pixel(_dc.MaxLength * PixelsPerCharacter); txt.CssClass = CssClassEditControl; txt.TabIndex = Convert.ToInt16( _iEditTabOrder * TabInterval ); td.Controls.Add(txt); txt.DataBinding += new EventHandler(txt_DataBinding); break; case "System.Int16": txt = new TextBox(); if (_dc.DefaultValue.Equals(DBNull.Value)) txt.ToolTip = _dc.ColumnName + " is of type " + _dc.DataType.ToString(); if (!_dc.Expression.Equals(string.Empty)) txt.ToolTip += ", a calculated field based on " + _dc.Expression.ToString(); txt.ID = "txt" + _dc.ColumnName; Fields.Add(txt.ID, _dc.ColumnName); txt.CssClass = CssClassEditControl; txt.TabIndex = Convert.ToInt16( _iEditTabOrder * TabInterval ); td.Controls.Add(txt); txt.MaxLength = 5; txt.Width = Unit.Pixel(40); rangeVal = new RangeValidator(); rangeVal.ControlToValidate = txt.ID; rangeVal.MaximumValue = "32767"; rangeVal.MinimumValue = "-32767"; rangeVal.Display = ValidatorDisplay.Dynamic; rangeVal.Text = "*"; rangeVal.ErrorMessage = "Entered value for " + _dc.ColumnName + " is not valid for an integer numeric field"; rangeVal.Type = ValidationDataType.Integer; td.Controls.Add(rangeVal); txt.DataBinding += new EventHandler(txt_DataBinding); break; case "System.Int32": txt = new TextBox(); if (_dc.DefaultValue.Equals(DBNull.Value)) txt.ToolTip = _dc.ColumnName + " is of type " + _dc.DataType.ToString(); if (!_dc.Expression.Equals(string.Empty)) txt.ToolTip += ", a calculated field based on " + _dc.Expression.ToString(); txt.ID = "txt" + _dc.ColumnName; Fields.Add(txt.ID, _dc.ColumnName); txt.CssClass = CssClassEditControl; txt.TabIndex = Convert.ToInt16( _iEditTabOrder * TabInterval ); td.Controls.Add(txt); txt.MaxLength = 10; txt.Width = Unit.Pixel(PixelsPerCharacter * txt.MaxLength ); rangeVal = new RangeValidator(); rangeVal.ControlToValidate = txt.ID; rangeVal.MaximumValue = "2147483647"; rangeVal.MinimumValue = "-2147483648"; rangeVal.Display = ValidatorDisplay.Dynamic; rangeVal.Text = "*"; rangeVal.ErrorMessage = "Entered value for " + _dc.ColumnName + " is not valid for an integer numeric field"; rangeVal.Type = ValidationDataType.Integer; td.Controls.Add(rangeVal); txt.DataBinding += new EventHandler(txt_DataBinding); break; case "System.Int64": txt = new TextBox(); if (_dc.DefaultValue.Equals(DBNull.Value)) txt.ToolTip = _dc.ColumnName + " is of type " + _dc.DataType.ToString(); if (!_dc.Expression.Equals(string.Empty)) txt.ToolTip += ", a calculated field based on " + _dc.Expression.ToString(); txt.ID = "txt" + _dc.ColumnName; Fields.Add(txt.ID, _dc.ColumnName); txt.CssClass = CssClassEditControl; txt.TabIndex = Convert.ToInt16( _iEditTabOrder * TabInterval ); td.Controls.Add(txt); txt.MaxLength = 19; txt.Width = Unit.Pixel(PixelsPerCharacter * 10); rangeVal = new RangeValidator(); rangeVal.ControlToValidate = txt.ID; rangeVal.MaximumValue = "9223372036854775807"; rangeVal.MinimumValue = "-9223372036854775808"; rangeVal.Display = ValidatorDisplay.Dynamic; rangeVal.Text = "*"; rangeVal.ErrorMessage = "Entered value for " + _dc.ColumnName + " is not valid for an integer numeric field"; rangeVal.Type = ValidationDataType.Integer; td.Controls.Add(rangeVal); txt.DataBinding += new EventHandler(txt_DataBinding); break; case "System.Decimal": txt = new TextBox(); if (_dc.DefaultValue.Equals(DBNull.Value)) txt.ToolTip = _dc.ColumnName + " is of type " + _dc.DataType.ToString(); if (!_dc.Expression.Equals(string.Empty)) txt.ToolTip += ", a calculated field based on " + _dc.Expression.ToString(); txt.ID = "txt" + _dc.ColumnName; Fields.Add(txt.ID, _dc.ColumnName); txt.CssClass = CssClassEditControl; txt.TabIndex = Convert.ToInt16( _iEditTabOrder * TabInterval ); td.Controls.Add(txt); txt.MaxLength = 19; txt.Width = Unit.Pixel(PixelsPerCharacter * 10); rexpval = new RegularExpressionValidator(); rexpval.ValidationExpression = @"^\d*.?\d{0,2}$"; rexpval.Display = ValidatorDisplay.Dynamic; rexpval.Text = "*"; rexpval.ErrorMessage = "Entered value for " + _dc.ColumnName + " is not valid for a decimal field"; rexpval.ControlToValidate = txt.ID; td.Controls.Add(rexpval); txt.DataBinding += new EventHandler(txt_DataBinding); break; case "System.DateTime": txt = new TextBox(); txt.ID = "txt" + _dc.ColumnName; Fields.Add(txt.ID, _dc.ColumnName); txt.MaxLength = 22; txt.Width = Unit.Pixel( PixelsPerCharacter * 35 ); txt.CssClass = CssClassEditControl; txt.TabIndex = Convert.ToInt16( _iEditTabOrder * TabInterval ); td.Controls.Add(txt); // this was causing trouble with the datetime format MM/dd/yyyy hh:mm:ss (military format) // need a different validation regex //rexpval = new RegularExpressionValidator(); //rexpval.ValidationExpression = @"^\(?\d{3}[\)\-\s]?\d{3}[-\s]?\d{4}$"; //rexpval.ControlToValidate = txt.ID; //rexpval.Display = ValidatorDisplay.Dynamic; //rexpval.Text = "*"; //rexpval.ErrorMessage = "Entered value for " + _dc.ColumnName + " is not a valid date"; //td.Controls.Add(rexpval); txt.DataBinding += new EventHandler(txt_DataBinding); break; default: txt = new TextBox(); txt.ID = "txt" + _dc.ColumnName; Fields.Add(txt.ID, _dc.ColumnName); txt.CssClass = CssClassEditControl; txt.TabIndex = Convert.ToInt16( _iEditTabOrder * TabInterval ); td.Controls.Add(txt); if (txt.MaxLength > 0) { txt.MaxLength = _dc.MaxLength; txt.Width = Unit.Pixel(_dc.MaxLength * PixelsPerCharacter); } txt.DataBinding += new EventHandler(txt_DataBinding); break; } // END switch ( _dc.DataType.ToString() ) } // END if( _dc.ReadOnly ) else break; } // END switch( _type ) return lbl; }