protected virtual bool ControlPropertiesValid ()
{
if (ControlToValidate.Length == 0) {
- throw new HttpException("ControlToValidate property cannot be emtpy");
+ throw new HttpException (String.Format ("ControlToValidate property of '{0}' cannot be blank.", ID));
}
CheckControlValidationProperty (ControlToValidate, "");
base.OnPreRender (e);
pre_render_called = true;
+
+ ControlPropertiesValid ();
render_uplevel = DetermineRenderUplevel ();
if (render_uplevel) {
+2006-02-15 Igor Zelmanovich <igorz@mainsoft.com>
+
+ * BaseValidator: ControlPropertiesValid is called on PreRender
+ * CompareValidator.cs:
+ * RangeValidator.cs: fixed ControlPropertiesValid, EvaluateIsValid.
+
2006-02-15 Igor Zelmanovich <igorz@mainsoft.com>
* BaseCompareValidator.cs: fixed: support for type=Currency on client side.
protected override bool ControlPropertiesValid ()
{
- if ((this.Operator != ValidationCompareOperator.DataTypeCheck) && !BaseCompareValidator.CanConvert(this.ValueToCompare, this.Type, this.CultureInvariantValues))
+ if ((this.Operator != ValidationCompareOperator.DataTypeCheck) && ControlToCompare.Length == 0 && !BaseCompareValidator.CanConvert (this.ValueToCompare, this.Type, this.CultureInvariantValues))
{
throw new HttpException(
String.Format("Unable to convert the value: {0} as a {1}", ValueToCompare, Enum.GetName(typeof(ValidationDataType), this.Type)));
}
- /* if the control id is the default "", or if we're
- * using the one Operator that ignores the control
- * id.. */
- if (ControlToCompare == "" || Operator == ValidationCompareOperator.DataTypeCheck)
- return base.ControlPropertiesValid();
- /* attempt to locate the ControlToCompare somewhere on the page */
- Control control = NamingContainer.FindControl (ControlToCompare);
- if (control == null)
- throw new HttpException (String.Format ("Unable to locate ControlToCompare with id `{0}'", ControlToCompare));
+ if (ControlToCompare.Length > 0) {
+ if (string.CompareOrdinal (ControlToCompare, ControlToValidate) == 0)
+ throw new HttpException (String.Format ("Control '{0}' cannot have the same value '{1}' for both ControlToValidate and ControlToCompare.", ID, ControlToCompare));
+ CheckControlValidationProperty (ControlToCompare, "");
+ }
return base.ControlPropertiesValid ();
}
protected override bool EvaluateIsValid ()
{
- /* wtf? */
- if (GetControlValidationValue (ControlToValidate) == "")
+ string control_value;
+
+ control_value = GetControlValidationValue (this.ControlToValidate);
+ if (control_value == null)
+ return true;
+ control_value = control_value.Trim ();
+ if (control_value.Length == 0)
return true;
string compare;
string control_value;
control_value = GetControlValidationValue(this.ControlToValidate);
- if (control_value == null || control_value == "") {
+ if (control_value == null)
return true;
- }
-
control_value = control_value.Trim();
+ if (control_value.Length == 0)
+ return true;
if (Compare(control_value, MinimumValue, ValidationCompareOperator.GreaterThanEqual, this.Type)) {
if (Compare(control_value, MaximumValue, ValidationCompareOperator.LessThanEqual, this.Type)) {
public void Page_ValidationCollection ()
{
WebTest t = new WebTest (PageInvoker.CreateOnLoad (ValidationCollectionload));
- t.Run ();
+ string html = t.Run ();
}
public static void ValidationCollectionload (Page p)
{
+ TextBox txt = new TextBox ();
+ txt.ID = "txt";
RequiredFieldValidator validator = new RequiredFieldValidator ();
validator.ID = "v";
+ validator.ControlToValidate = "txt";
RequiredFieldValidator validator1 = new RequiredFieldValidator ();
- validator.ID = "v1";
- p.Controls.Add (validator);
- p.Controls.Add (validator1);
+ validator1.ID = "v1";
+ validator1.ControlToValidate = "txt";
+ p.Form.Controls.Add (txt);
+ p.Form.Controls.Add (validator);
+ p.Form.Controls.Add (validator1);
Assert.AreEqual (2, p.Validators.Count, "Validators collection count fail");
Assert.AreEqual (true, p.Validators[0].IsValid, "Validators collection value#1 fail");
Assert.AreEqual (true, p.Validators[1].IsValid, "Validators collection value#2 fail");