2006-02-15 Igor Zelmanovich <igorz@mainsoft.com>
authorIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Thu, 15 Feb 2007 15:09:13 +0000 (15:09 -0000)
committerIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Thu, 15 Feb 2007 15:09:13 +0000 (15:09 -0000)
* BaseValidator: ControlPropertiesValid is called on PreRender
* CompareValidator.cs:
* RangeValidator.cs: fixed ControlPropertiesValid, EvaluateIsValid.

svn path=/trunk/mcs/; revision=72917

mcs/class/System.Web/System.Web.UI.WebControls/BaseValidator.cs
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/System.Web.UI.WebControls/CompareValidator.cs
mcs/class/System.Web/System.Web.UI.WebControls/RangeValidator.cs
mcs/class/System.Web/Test/System.Web.UI/PageTest.cs

index e2e2ea1dad3cecea6406ae574d92bcd615c4594b..778be8c8c7e718d81e744e4839f47e6e5ee4f3fa 100644 (file)
@@ -267,7 +267,7 @@ namespace System.Web.UI.WebControls {
                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, "");
@@ -378,6 +378,8 @@ namespace System.Web.UI.WebControls {
                        base.OnPreRender (e);
 
                        pre_render_called = true;
+                       
+                       ControlPropertiesValid ();
 
                        render_uplevel = DetermineRenderUplevel ();
                        if (render_uplevel) {
index 0e209cf3dea543f5d3e6ba5f3314818ae6966383..c8a0e41db8cab54d702a4117b1db45295e699037 100644 (file)
@@ -1,3 +1,9 @@
+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.
index 8970c6f423579260eefc5df94f1e800ef4d5d183..2369db16f53a557bc0398d081b7f1b0394e284fc 100644 (file)
@@ -62,29 +62,30 @@ namespace System.Web.UI.WebControls {
 
                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;
index b5a353fb0b4ae75b9d18b80f03a6801756e63e63..841d33760f972bb7af2efb9433d2e30c83c8698b 100644 (file)
@@ -115,11 +115,11 @@ namespace System.Web.UI.WebControls {
                        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)) {
index e5b7482137776a189791f3b25a47420cab282e63..b3c1451c91eae201e2bb13de3f1d2dbb0cc6a35b 100644 (file)
@@ -366,17 +366,22 @@ namespace MonoTests.System.Web.UI {
                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");