2 // System.Web.UI.WebControls.CustomValidator.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 [DefaultEvent("ServerValidate")]
41 [ToolboxData("<{0}:CustomValidator runat=\"server\""
42 + "ErrorMessage=\"CustomValidator\">"
43 + "</{0}:CustomValidator>")]
44 public class CustomValidator
: BaseValidator
46 private static readonly object ServerValidateEvent
= new object();
48 public CustomValidator()
52 [DefaultValue (""), WebCategory ("Behavior")]
53 [WebSysDescription ("A client script that performs the validation.")]
54 public string ClientValidationFunction
58 object o
= ViewState
["ClientValidationFunction"];
67 ViewState
["ClientValidationFunction"] = value;
71 [WebSysDescription ("Raised for validation on the server.")]
72 public event ServerValidateEventHandler ServerValidate
76 Events
.AddHandler(ServerValidateEvent
, value);
80 Events
.RemoveHandler(ServerValidateEvent
, value);
84 protected override void AddAttributesToRender(HtmlTextWriter writer
)
86 base.AddAttributesToRender(writer
);
89 writer
.AddAttribute("evaluationfunction", "CustomValidatorEvaluateIsValid");
90 if(ClientValidationFunction
.Length
> 0)
92 writer
.AddAttribute("clientvalidationfunction", ClientValidationFunction
);
97 protected override bool ControlPropertiesValid()
99 if(ControlToValidate
.Length
> 0)
101 CheckControlValidationProperty(ControlToValidate
, "ControlToValidate");
106 protected virtual bool OnServerValidate(string value)
110 ServerValidateEventHandler sveh
= (ServerValidateEventHandler
)(Events
[ServerValidateEvent
]);
113 ServerValidateEventArgs args
= new ServerValidateEventArgs(value, true);
121 protected override bool EvaluateIsValid()
123 string ctrl
= ControlToValidate
;
126 ctrl
= GetControlValidationValue(ctrl
);
127 if(ctrl
== null || ctrl
.Length
== 0)
132 return OnServerValidate(ctrl
);