2001-12-01 Gaurav Vaish <gvaish@iitk.ac.in>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / BaseValidator.cs
1 /**\r
2  * Namespace: System.Web.UI.WebControls\r
3  * Class:     BaseValidator\r
4  * \r
5  * Author:  Gaurav Vaish\r
6  * Maintainer: gvaish@iitk.ac.in\r
7  * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>\r
8  * Status:  20%\r
9  * \r
10  * (C) Gaurav Vaish (2001)\r
11  */\r
12 \r
13 using System;\r
14 using System.ComponentModel;\r
15 using System.Web;\r
16 using System.Web.UI;\r
17 using System.Drawing;\r
18 \r
19 namespace System.Web.UI.WebControls\r
20 {\r
21         public abstract class BaseValidator: Label, IValidator\r
22         {\r
23                 //\r
24                 private PropertyDescriptor pDesc;\r
25                 private string ctValid = String.Empty;\r
26                 private ValidatorDisplay vDisp = ValidatorDisplay.Static;\r
27                 private bool enableClientScript; //TODO: check the default value := false;\r
28                 private bool enabled = true;\r
29                 private string errorMessage = String.Empty;\r
30                 private Color foreColor = Color.Red;\r
31                 private bool isValid = true;\r
32                 private bool propertiesValid;\r
33                 private bool renderUplevel;\r
34 \r
35                 public static PropertyDescriptor GetValidationProperty(object component)\r
36                 {\r
37                         //TODO: Have to workout this one!\r
38                         return null;\r
39                 }\r
40                 \r
41                 public string ControlToValidate\r
42                 {\r
43                         get\r
44                         {\r
45                                 return ctValid;\r
46                         }\r
47                         set\r
48                         {\r
49                                 ctValid = value;\r
50                         }\r
51                 }\r
52                 \r
53                 public ValidatorDisplay Display\r
54                 {\r
55                         get\r
56                         {\r
57                                 return vDisp;\r
58                         }\r
59                         set\r
60                         {\r
61                                 //TODO: Throw new exception ArgumentException("....") if the value is not valid\r
62                                 vDisp = value;\r
63                         }\r
64                 }\r
65                 \r
66                 public bool EnableClientScript\r
67                 {\r
68                         get\r
69                         {\r
70                                 return enableClientScript;\r
71                         }\r
72                         set\r
73                         {\r
74                                 enableClientScript = value;\r
75                         }\r
76                 }\r
77                 \r
78                 public override bool Enabled\r
79                 {\r
80                         get\r
81                         {\r
82                                 return enabled;\r
83                         }\r
84                         set\r
85                         {\r
86                                 enabled = value;\r
87                         }\r
88                 }\r
89                 \r
90                 public string ErrorMessage\r
91                 {\r
92                         get\r
93                         {\r
94                                 return errorMessage;\r
95                         }\r
96                         set\r
97                         {\r
98                                 errorMessage = value;\r
99                         }\r
100                 }\r
101                 \r
102                 public override Color ForeColor\r
103                 {\r
104                         get\r
105                         {\r
106                                 return foreColor;\r
107                         }\r
108                         set\r
109                         {\r
110                                 foreColor = value;\r
111                         }\r
112                 }\r
113                 \r
114                 public bool IsValid\r
115                 {\r
116                         get\r
117                         {\r
118                                 return isValid;\r
119                         }\r
120                         set\r
121                         {\r
122                                 isValid = value;\r
123                         }\r
124                 }\r
125                 \r
126                 public void Validate()\r
127                 {\r
128                         // TODO: write the validation code\r
129                         // TODO: update the value of isValid\r
130                 }\r
131                 \r
132                 protected BaseValidator()\r
133                 {\r
134                         // Dummy Constructor\r
135                 }\r
136                 \r
137                 protected bool PropertiesValid\r
138                 {\r
139                         get\r
140                         {\r
141                                 // TODO: throw HttpException, but when? How do I know about all the controls?\r
142                                 return propertiesValid;\r
143                         }\r
144                 }\r
145                 \r
146                 protected bool RenderUplevel\r
147                 {\r
148                         get\r
149                         {\r
150                                 //TODO: To set the value of renderUplevel. Problem: when, how?\r
151                                 return renderUplevel;\r
152                         }\r
153                 }\r
154                 \r
155                 protected void CheckControlValidationProperty(string name, string propertyName)\r
156                 {\r
157                         //TODO: I think it needs to be overridden. I may be wrong!\r
158                         //TODO: When to throw HttpException(...)\r
159                 }\r
160 \r
161                 protected virtual bool ControlPropertiesValid()\r
162                 {\r
163                         // Do I need to do anything? But what?\r
164                         // What do I do with ControlToValidate?\r
165                         return true;\r
166                 }\r
167 \r
168                 protected virtual bool DetermineRenderUplevel()\r
169                 {\r
170                         // From where?\r
171                         return true;\r
172                 }\r
173 \r
174                 protected abstract bool EvaluateIsValid();\r
175 \r
176                 protected string GetControlRenderID(string name)\r
177                 {\r
178                         // TODO: What value? What is it?\r
179                 }\r
180 \r
181                 protected string GetControlValidationValue(string name)\r
182                 {\r
183                         // TODO: What value? What is it?\r
184                 }\r
185 \r
186                 protected void RegisterValidatorCommonScript()\r
187                 {\r
188                         // TODO: Still wondering!\r
189                         // Note: This method is primarily used by control developers\r
190                 }\r
191 \r
192                 protected void RegisterValidatorDeclaration()\r
193                 {\r
194                         // TODO: Still wondering!\r
195                         // Note: This method is primarily used by control developers\r
196                         // The documentation in M$ refers to: Page_Validators array\r
197                 }\r
198         }\r
199 }\r