2010-02-18 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / ValidationSummary.cs
index 74f90698bf559725fdc66456edf44d5bbee6080b..10d084495f7338f73e39a30d41e89080153896af 100644 (file)
 //
 //
 
-using System;
 using System.Collections;
 using System.ComponentModel;
 using System.Drawing;
 using System.Globalization;
-using System.Web;
-using System.Web.UI;
-using System.Web.UI.WebControls;
+using System.Security.Permissions;
 
 namespace System.Web.UI.WebControls {
+
+       // CAS
+       [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
 #if NET_2_0
        [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
 #endif
@@ -148,7 +149,7 @@ namespace System.Web.UI.WebControls {
 #if NET_2_0
                [DefaultValue ("")]
                [Themeable (false)]
-               public string ValidationGroup
+               public virtual string ValidationGroup
                {
                        get {
                                return ViewState.GetString("ValidationGroup", string.Empty);
@@ -162,14 +163,36 @@ namespace System.Web.UI.WebControls {
                #endregion      // Public Instance Properties
 
                #region Public Instance Methods
+               [MonoTODO ()]
+               // for 2.0: not XHTML attributes must be registered with RegisterExpandoAttribute 
+               // when it will be implemented, in this case WebUIValidation_2.0.js muist be refactored
                protected override void AddAttributesToRender(HtmlTextWriter writer) {
                        base.AddAttributesToRender (writer);
 
+#if NET_2_0
+                       if (EnableClientScript && pre_render_called && Page.AreValidatorsUplevel (ValidationGroup)) {
+#else
                        if (EnableClientScript && pre_render_called && Page.AreValidatorsUplevel ()) {
+#endif
                                /* force an ID here if we weren't assigned one */
                                if (ID == null)
                                        writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
+#if NET_2_0
+                               if (ValidationGroup != String.Empty)
+                                       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);
 
@@ -181,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          
@@ -204,6 +241,10 @@ namespace System.Web.UI.WebControls {
                protected
 #endif         
                override void Render(HtmlTextWriter writer) {
+#if NET_2_0
+                       if (!Enabled)
+                               return;
+#endif
                        ValidatorCollection     validators;
                        ArrayList               errors;
 
@@ -213,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);
@@ -227,9 +265,25 @@ namespace System.Web.UI.WebControls {
 
                        has_errors = errors.Count > 0;
 
+#if NET_2_0
+                       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))