Merge pull request #2916 from ludovic-henry/fix-40306
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / EditCommandColumn.cs
index ded2f49a8bb2928ff6016ea5a7a1e287a24a6136..bdefbab5bdddd5cb7ab17e26a88c1ba1f3b4dcad 100644 (file)
@@ -17,7 +17,7 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2005-2010 Novell, Inc. (http://www.novell.com)
 //
 // Authors:
 //     Peter Bartok    (pbartok@novell.com)
 using System.ComponentModel;
 using System.Security.Permissions;
 
-namespace System.Web.UI.WebControls {
-
+namespace System.Web.UI.WebControls
+{
        // CAS
        [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
-       public class EditCommandColumn : DataGridColumn {
+       public class EditCommandColumn : DataGridColumn
+       {
                #region Public Constructors
-               public EditCommandColumn() {
+               public EditCommandColumn()
+               {
                }
                #endregion      // Public Constructors
 
                #region Public Instance Properties
+               [DefaultValue (ButtonColumnType.LinkButton)]
                public virtual ButtonColumnType ButtonType {
                        get {
                                object obj;
 
                                obj = ViewState["ButtonType"];
-                               if (obj != null) {
+                               if (obj != null)
                                        return (ButtonColumnType)obj;
-                               }
                                return ButtonColumnType.LinkButton;
                        }
 
-                       set {
-                               ViewState["ButtonType"] = value;
-                       }
+                       set { ViewState["ButtonType"] = value; }
                }
 
-#if NET_2_0
                [DefaultValue ("")]
                [Localizable (true)]
-#endif
                public virtual string CancelText {
-                       get {
-                               return ViewState.GetString("CancelText", string.Empty);
-                       }
+                       get { return ViewState.GetString("CancelText", String.Empty); }
+                       set { ViewState["CancelText"] = value; }
+               }
 
-                       set {
-                               ViewState["CancelText"] = value;
-                       }
+               [DefaultValue(true)]
+               public virtual bool CausesValidation {
+                       get { return ViewState.GetBool ("CausesValidation", true); }
+                       set { ViewState ["CausesValidation"] = value; } 
+               }
+
+               [DefaultValue("")]
+               public virtual string ValidationGroup {
+                       get { return ViewState.GetString ("ValidationGroup", String.Empty); }
+                       set { ViewState ["ValidationGroup"] = value; } 
                }
 
-#if NET_2_0
                [DefaultValue ("")]
                [Localizable (true)]
-#endif
                public virtual string EditText {
-                       get {
-                               return ViewState.GetString("EditText", string.Empty);
-                       }
-
-                       set {
-                               ViewState["EditText"] = value;
-                       }
+                       get { return ViewState.GetString("EditText", String.Empty); }
+                       set { ViewState["EditText"] = value; }
                }
 
-#if NET_2_0
                [DefaultValue ("")]
                [Localizable (true)]
-#endif
                public virtual string UpdateText {
-                       get {
-                               return ViewState.GetString("UpdateText", string.Empty);
-                       }
-
-                       set {
-                               ViewState["UpdateText"] = value;
-                       }
+                       get { return ViewState.GetString("UpdateText", String.Empty); }
+                       set { ViewState["UpdateText"] = value; }
                }
                #endregion      // Public Instance Properties
 
                #region Public Instance Methods
 
                // Modeled after Ben's CommandField.InitializeCell. Saved me a lot of figuring-out time :-)
-               public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) {
+               public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType)
+               {
                        base.InitializeCell (cell, columnIndex, itemType);
 
                        switch(itemType) {
@@ -121,7 +113,7 @@ namespace System.Web.UI.WebControls {
                                }
 
                                case ListItemType.EditItem: {
-                                       cell.Controls.Add(CreateButton(ButtonType, UpdateText, "Update", true));
+                                       cell.Controls.Add (CreateButton (ButtonType, UpdateText, "Update", CausesValidation));
                                        cell.Controls.Add(new LiteralControl(" "));
                                        cell.Controls.Add(CreateButton(ButtonType, CancelText, "Cancel", false));
                                        break;
@@ -131,7 +123,8 @@ namespace System.Web.UI.WebControls {
                #endregion      // Public Instance Methods
 
                #region Private Methods
-               private Control CreateButton(ButtonColumnType type, string text, string command, bool valid) {
+               Control CreateButton(ButtonColumnType type, string text, string command, bool valid)
+               {
                        Button b;
                        LinkButton d;
 
@@ -140,6 +133,8 @@ namespace System.Web.UI.WebControls {
                                d.Text = text;
                                d.CommandName = command;
                                d.CausesValidation = valid;
+                               if (valid)
+                                       d.ValidationGroup = ValidationGroup;
                                return d;
                        }
 
@@ -147,6 +142,9 @@ namespace System.Web.UI.WebControls {
                        b.Text = text;
                        b.CommandName = command;
                        b.CausesValidation = valid;
+                       if (valid)
+                               b.ValidationGroup = ValidationGroup;
+
                        return b;
                }
                #endregion      // Private Methods