(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web / System.Web.UI.WebControls / CustomValidator.cs
blob0dcb4e9fdde94f590cb176c59907441aa4002e93
1 //
2 // System.Web.UI.WebControls.CustomValidator.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
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.
33 using System;
34 using System.Web;
35 using System.Web.UI;
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
56 get
58 object o = ViewState["ClientValidationFunction"];
59 if(o != null)
61 return (string)o;
63 return String.Empty;
65 set
67 ViewState["ClientValidationFunction"] = value;
71 [WebSysDescription ("Raised for validation on the server.")]
72 public event ServerValidateEventHandler ServerValidate
74 add
76 Events.AddHandler(ServerValidateEvent, value);
78 remove
80 Events.RemoveHandler(ServerValidateEvent, value);
84 protected override void AddAttributesToRender(HtmlTextWriter writer)
86 base.AddAttributesToRender(writer);
87 if(RenderUplevel)
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");
103 return true;
106 protected virtual bool OnServerValidate(string value)
108 if(Events != null)
110 ServerValidateEventHandler sveh = (ServerValidateEventHandler)(Events[ServerValidateEvent]);
111 if(sveh != null)
113 ServerValidateEventArgs args = new ServerValidateEventArgs(value, true);
114 sveh(this, args);
115 return args.IsValid;
118 return true;
121 protected override bool EvaluateIsValid()
123 string ctrl = ControlToValidate;
124 if(ctrl.Length > 0)
126 ctrl = GetControlValidationValue(ctrl);
127 if(ctrl== null || ctrl.Length == 0)
129 return true;
132 return OnServerValidate(ctrl);