2002-10-28 Gaurav Vaish <gvaish_mono@lycos.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / CompareValidator.cs
1 /**
2 * Namespace: System.Web.UI.WebControls
3 * Class:     CompareValidator
4 *
5 * Author:  Gaurav Vaish
6 * Maintainer: gvaish@iitk.ac.in
7 * Implementation: yes
8 * Status:  80%
9 *
10 * (C) Gaurav Vaish (2001)
11 */
12
13 using System;
14 using System.Web;
15 using System.Web.UI;
16
17 namespace System.Web.UI.WebControls
18 {
19         [ToolboxData("<{0}:CompareValidator runat=\"server\""
20                      + "ErrorMessage=\"CompareValidator\"></{0}:CompareValidator>")]
21         public class CompareValidator: BaseCompareValidator
22         {
23                 public CompareValidator()
24                 {
25                         // Intitalize();
26                 }
27
28                 public string ControlToCompare
29                 {
30                         get
31                         {
32                                 object o = ViewState["ControlToCompare"];
33                                 if(o!=null)
34                                         return (string)o;
35                                 return String.Empty;
36                         }
37
38                         set
39                         {
40                                 ViewState["ControlToCompare"] = value;
41                         }
42                 }
43
44                 public ValidationCompareOperator Operator
45                 {
46                         get
47                         {
48                                 object o = ViewState["Operator"];
49                                 if(o!=null)
50                                         return (ValidationCompareOperator)o;
51                                 return ValidationCompareOperator.Equal;
52                         }
53                         set
54                         {
55                                 if(!System.Enum.IsDefined(typeof(ValidationCompareOperator), value))
56                                         throw new ArgumentException();
57                                 ViewState["Operator"] = value;
58                         }
59                 }
60
61                 public string ValueToCompare
62                 {
63                         get
64                         {
65                                 object o = ViewState["ValueToCompare"];
66                                 if(o!=null)
67                                         return (string)o;
68                                 return String.Empty;
69                         }
70                         set
71                         {
72                                 ViewState["ValueToCompare"] = value;
73                         }
74                 }
75
76                 protected override bool EvaluateIsValid()
77                 {
78                         string ctrl = GetControlValidationValue(ControlToValidate);
79                         if(ctrl != null && ctrl.Length > 0)
80                         {
81                                 string cmp = (ControlToCompare.Length > 0 ?
82                                               ControlToCompare : ValueToCompare);
83                                 return BaseCompareValidator.Compare(ctrl, cmp,
84                                                                     Operator, Type);
85                         }
86                         return true;
87                 }
88         }
89 }