3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Namespace : System.Web.UI.MobileControls
25 * Class : BaseValidator
26 * Author : Gaurav Vaish
28 * Copyright : 2003 with Gaurav Vaish, and with
32 using System
.ComponentModel
;
34 using System
.Web
.Mobile
;
35 using System
.Web
.UI
.WebControls
;
37 namespace System
.Web
.UI
.MobileControls
39 public abstract class BaseValidator
: TextControl
, IValidator
41 private System
.Web
.UI
.WebControls
.BaseValidator webBaseValidator
;
42 private bool isValid
= true;
44 protected BaseValidator()
46 StyleReference
= "error";
47 webBaseValidator
= CreateWebValidator();
48 if(webBaseValidator
== null)
49 this.webBaseValidator
= new DefaultWebValidator();
50 Controls
.Add(webBaseValidator
);
51 webBaseValidator
.Display
= ValidatorDisplay
.Dynamic
;
54 private class DefaultWebValidator
55 : System
.Web
.UI
.WebControls
.BaseValidator
57 protected override bool EvaluateIsValid()
63 protected virtual System
.Web
.UI
.WebControls
.BaseValidator
CreateWebValidator()
68 public string ErrorMessage
72 return webBaseValidator
.ErrorMessage
;
76 webBaseValidator
.ErrorMessage
= value;
92 public void Validate()
96 Control parent
= Parent
;
105 parent
= parent
.Parent
;
115 protected abstract bool EvaluateIsValid();
117 public string ControlToValidate
121 return webBaseValidator
.ControlToValidate
;
125 webBaseValidator
.ControlToValidate
= value;
129 public ValidatorDisplay Display
133 return webBaseValidator
.Display
;
137 webBaseValidator
.Display
= value;
141 public override string StyleReference
145 return base.StyleReference
;
149 base.StyleReference
= value;
153 public override int VisibleWeight
161 protected void CheckControlValidationProperty(string name
,
164 Control ctrl
= NamingContainer
.FindControl(name
);
168 throw new ArgumentException("BaseValidator_ControlNotFound");
170 PropertyDescriptor pd
= System
.Web
.UI
.WebControls
.BaseValidator
.GetValidationProperty(ctrl
);
174 throw new ArgumentException("BaseValidator_BadControlType");
178 protected virtual bool ControlPropertiesValid()
180 string ctrl
= ControlToValidate
;
184 throw new ArgumentException("BaseValidator_ControlToValidateBlank");
186 CheckControlValidationProperty(ctrl
, "ControlToValidate");
190 internal bool EvaluateIsValidInternal()
194 webBaseValidator
.Validate();
198 ID
= webBaseValidator
.ID
;
199 webBaseValidator
.ID
= thisID
;
202 webBaseValidator
.Validate();
206 ID
= webBaseValidator
.ID
;
207 webBaseValidator
.ID
= thisID
;
210 return webBaseValidator
.IsValid
;
213 protected override void OnInit(EventArgs e
)
215 Page
.Validators
.Add(this);
219 protected override void OnPreRender(EventArgs e
)
221 if(MobilePage
.ActiveForm
== Form
)
222 ControlPropertiesValid();