2 // System.Web.UI.WebControls.CompareValidator.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System
.ComponentModel
;
38 namespace System
.Web
.UI
.WebControls
40 [ToolboxData("<{0}:CompareValidator runat=\"server\""
41 + "ErrorMessage=\"CompareValidator\"></{0}:CompareValidator>")]
42 public class CompareValidator
: BaseCompareValidator
44 public CompareValidator()
49 [DefaultValue (""), WebCategory ("Behavior")]
50 [TypeConverter (typeof (ValidatedControlConverter
))]
51 [WebSysDescription ("The ID of a control that is compared.")]
52 public string ControlToCompare
56 object o
= ViewState
["ControlToCompare"];
64 ViewState
["ControlToCompare"] = value;
68 [DefaultValue (typeof (ValidationCompareOperator
), "Equal"), WebCategory ("Behavior")]
69 [WebSysDescription ("The operator that is used for comparison.")]
70 public ValidationCompareOperator Operator
74 object o
= ViewState
["Operator"];
76 return (ValidationCompareOperator
)o
;
77 return ValidationCompareOperator
.Equal
;
81 if(!System
.Enum
.IsDefined(typeof(ValidationCompareOperator
), value))
82 throw new ArgumentException();
83 ViewState
["Operator"] = value;
87 [DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
88 [WebSysDescription ("The value that is compared to.")]
89 public string ValueToCompare
93 object o
= ViewState
["ValueToCompare"];
100 ViewState
["ValueToCompare"] = value;
104 protected override bool EvaluateIsValid ()
106 string ctrl
= GetControlValidationValue (ControlToValidate
);
107 if (ctrl
== null || ctrl
.Length
== 0)
111 if (ControlToCompare
.Length
> 0) {
112 cmp
= GetControlValidationValue (ControlToCompare
);
114 cmp
= ValueToCompare
;
117 return Compare (ctrl
, cmp
, Operator
, Type
);
121 protected override void AddAttributesToRender (HtmlTextWriter writer
)
123 base.AddAttributesToRender (writer
);
127 protected override bool ControlPropertiesValid ()
129 return base.ControlPropertiesValid ();