2010-02-18 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / CustomValidator.cs
index 9015880fc804c361a50318e59e81ceffd34c11c4..e4f0581d8936b6bcc24d707fc83242a1783f3a24 100644 (file)
@@ -39,6 +39,20 @@ namespace System.Web.UI.WebControls {
        [ToolboxData("<{0}:CustomValidator runat=server ErrorMessage=\"CustomValidator\"></{0}:CustomValidator>")]
 #endif
        public class CustomValidator : BaseValidator {
+               static readonly object serverValidateEvent = new object ();
+
+               EventHandlerList events = new EventHandlerList ();
+               
+               #region Events
+               [WebSysDescription ("")]
+               [WebCategory ("Behavior")]
+                       public event ServerValidateEventHandler ServerValidate {
+                       add { events.AddHandler (serverValidateEvent, value); }
+                       remove { events.RemoveHandler (serverValidateEvent, value); }
+               }
+               
+               #endregion      // Events
+
                #region Public Constructors
                public CustomValidator() {
                }
@@ -72,13 +86,21 @@ namespace System.Web.UI.WebControls {
 
                        if (base.RenderUplevel) {
                                string s;
-
-                               writer.AddAttribute("evaluationfunction", "CustomValidatorEvaluateIsValid");
+                               
+#if NET_2_0
+                               RegisterExpandoAttribute (ClientID, "evaluationfunction", "CustomValidatorEvaluateIsValid");
+                               if (ValidateEmptyText)
+                                       RegisterExpandoAttribute (ClientID, "validateemptytext", "true");
+                               s = ClientValidationFunction;
+                               if (!String.IsNullOrEmpty (s))
+                                       RegisterExpandoAttribute (ClientID, "clientvalidationfunction", s, true);
+#else
+                               writer.AddAttribute ("evaluationfunction", "CustomValidatorEvaluateIsValid", false);
 
                                s = ClientValidationFunction;
-                               if (s != string.Empty) {
+                               if (s != String.Empty)
                                        writer.AddAttribute("clientvalidationfunction", s);
-                               }
+#endif
                        }
                }
 
@@ -102,21 +124,16 @@ namespace System.Web.UI.WebControls {
                }
 
                protected virtual bool OnServerValidate(string value) {
-                       if (ServerValidate != null) {
+                       ServerValidateEventHandler eh = events [serverValidateEvent] as ServerValidateEventHandler;
+                       if (eh != null) {
                                ServerValidateEventArgs e;
 
                                e = new ServerValidateEventArgs(value, true);
-                               ServerValidate(this, e);
+                               eh (this, e);
                                return e.IsValid;
                        }
                        return true;
                }
                #endregion      // Public Instance Methods
-
-               #region Events
-               [WebSysDescription ("")]
-               [WebCategory ("Behavior")]
-               public event ServerValidateEventHandler ServerValidate;
-               #endregion      // Events
        }
 }