2010-02-18 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / ValidationSummary.cs
index 6dbf39d18876189a65a075e2406e6cb350dca8ff..10d084495f7338f73e39a30d41e89080153896af 100644 (file)
@@ -179,8 +179,20 @@ namespace System.Web.UI.WebControls {
                                        writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
 #if NET_2_0
                                if (ValidationGroup != String.Empty)
-                                       writer.AddAttribute ("validationgroup", ValidationGroup);
-#endif
+                                       RegisterExpandoAttribute (ClientID, "validationGroup", ValidationGroup);
+
+                               if (HeaderText.Length > 0)
+                                       RegisterExpandoAttribute (ClientID, "headertext", HeaderText);
+
+                               if (ShowMessageBox)
+                                       RegisterExpandoAttribute (ClientID, "showmessagebox", "True");
+
+                               if (!ShowSummary)
+                                       RegisterExpandoAttribute (ClientID, "showsummary", "False");
+
+                               if (DisplayMode != ValidationSummaryDisplayMode.BulletList)
+                                       RegisterExpandoAttribute (ClientID, "displaymode", DisplayMode.ToString ());
+#else
                                if (HeaderText != "")
                                        writer.AddAttribute ("headertext", HeaderText);
 
@@ -192,12 +204,26 @@ namespace System.Web.UI.WebControls {
 
                                if (DisplayMode != ValidationSummaryDisplayMode.BulletList)
                                        writer.AddAttribute ("displaymode", DisplayMode.ToString());
+#endif
 
                                if (!has_errors)
                                        writer.AddStyleAttribute ("display", "none");
                        }
                }
 
+#if NET_2_0
+               internal void RegisterExpandoAttribute (string controlId, string attributeName, string attributeValue) {
+                       RegisterExpandoAttribute (controlId, attributeName, attributeValue, false);
+               }
+
+               internal void RegisterExpandoAttribute (string controlId, string attributeName, string attributeValue, bool encode) {
+                       if (Page.ScriptManager != null)
+                               Page.ScriptManager.RegisterExpandoAttributeExternal (this, controlId, attributeName, attributeValue, encode);
+                       else
+                               Page.ClientScript.RegisterExpandoAttribute (controlId, attributeName, attributeValue, encode);
+               }
+#endif
+
 #if NET_2_0
                protected internal
 #else          
@@ -228,9 +254,6 @@ namespace System.Web.UI.WebControls {
 #else
                        validators = Page.Validators;
 #endif
-                       if (validators.Count == 0) {
-                               return;
-                       }
 
                        // We have validators
                        errors = new ArrayList(validators.Count);
@@ -246,9 +269,21 @@ namespace System.Web.UI.WebControls {
                        if (EnableClientScript && pre_render_called && Page.AreValidatorsUplevel (ValidationGroup)) {
 #else
                        if (EnableClientScript && pre_render_called && Page.AreValidatorsUplevel ()) {
+#endif
+#if NET_2_0
+                               if (Page.ScriptManager != null) {
+                                       Page.ScriptManager.RegisterArrayDeclarationExternal (this, "Page_ValidationSummaries", String.Concat ("document.getElementById ('", ClientID, "')"));
+                                       Page.ScriptManager.RegisterStartupScriptExternal (this, typeof (BaseValidator), ClientID + "DisposeScript",
+@"
+document.getElementById('" + ClientID + @"').dispose = function() {
+       Array.remove(Page_ValidationSummaries, document.getElementById('" + ClientID + @"'));
+}
+", true);
+                                       }
+                               else
 #endif
                                Page.ClientScript.RegisterArrayDeclaration ("Page_ValidationSummaries",
-                                                                           String.Format ("document.getElementById ('{0}')", ClientID));
+                                                                           String.Concat ("document.getElementById ('", ClientID, "')"));
                        }
 
                        if ((ShowSummary && has_errors) || (EnableClientScript && pre_render_called))