Copied remotely
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / CompareValidator.cs
1 //
2 // System.Web.UI.WebControls.CompareValidator.cs
3 //
4 // Authors:
5 //   Gaurav Vaish (gvaish@iitk.ac.in)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
10 //
11
12 //
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:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
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.
31 //
32
33 using System;
34 using System.Web;
35 using System.Web.UI;
36 using System.ComponentModel;
37
38 namespace System.Web.UI.WebControls
39 {
40         [ToolboxData("<{0}:CompareValidator runat=\"server\""
41                      + "ErrorMessage=\"CompareValidator\"></{0}:CompareValidator>")]
42         public class CompareValidator: BaseCompareValidator
43         {
44                 public CompareValidator()
45                 {
46                         // Intitalize();
47                 }
48
49                 [DefaultValue (""), WebCategory ("Behavior")]
50                 [TypeConverter (typeof (ValidatedControlConverter))]
51                 [WebSysDescription ("The ID of a control that is compared.")]
52                 public string ControlToCompare
53                 {
54                         get
55                         {
56                                 object o = ViewState["ControlToCompare"];
57                                 if(o!=null)
58                                         return (string)o;
59                                 return String.Empty;
60                         }
61
62                         set
63                         {
64                                 ViewState["ControlToCompare"] = value;
65                         }
66                 }
67
68                 [DefaultValue (typeof (ValidationCompareOperator), "Equal"), WebCategory ("Behavior")]
69                 [WebSysDescription ("The operator that is used for comparison.")]
70                 public ValidationCompareOperator Operator
71                 {
72                         get
73                         {
74                                 object o = ViewState["Operator"];
75                                 if(o!=null)
76                                         return (ValidationCompareOperator)o;
77                                 return ValidationCompareOperator.Equal;
78                         }
79                         set
80                         {
81                                 if(!System.Enum.IsDefined(typeof(ValidationCompareOperator), value))
82                                         throw new ArgumentException();
83                                 ViewState["Operator"] = value;
84                         }
85                 }
86
87                 [DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
88                 [WebSysDescription ("The value that is compared to.")]
89                 public string ValueToCompare
90                 {
91                         get
92                         {
93                                 object o = ViewState["ValueToCompare"];
94                                 if(o!=null)
95                                         return (string)o;
96                                 return String.Empty;
97                         }
98                         set
99                         {
100                                 ViewState["ValueToCompare"] = value;
101                         }
102                 }
103
104                 protected override bool EvaluateIsValid ()
105                 {
106                         string ctrl = GetControlValidationValue (ControlToValidate);
107                         if (ctrl == null || ctrl.Length == 0)
108                                 return true;
109
110                         string cmp;
111                         if (ControlToCompare.Length > 0) {
112                                 cmp = GetControlValidationValue (ControlToCompare);
113                         } else {
114                                 cmp = ValueToCompare;
115                         }
116
117                         return Compare (ctrl, cmp, Operator, Type);
118                 }
119
120                 [MonoTODO]
121                 protected override void AddAttributesToRender (HtmlTextWriter writer)
122                 {
123                         base.AddAttributesToRender (writer);
124                 }
125
126                 [MonoTODO]
127                 protected override bool ControlPropertiesValid ()
128                 {
129                         return base.ControlPropertiesValid ();
130                 }
131         }
132 }