Merge pull request #2084 from joelmartinez/mdoc-deletetestfix
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / CommandField.cs
index 835cf186afaefd640185623389b6c540dd3e9138..a046105bdb8391566950b6ec02ad339a98563139 100644 (file)
@@ -4,7 +4,7 @@
 // Authors:
 //     Lluis Sanchez Gual (lluis@novell.com)
 //
-// (C) 2005 Novell, Inc (http://www.novell.com)
+// (C) 2005-2010 Novell, Inc (http://www.novell.com)
 //
 
 //
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 using System.Collections;
 using System.Collections.Specialized;
 using System.Web.UI;
 using System.ComponentModel;
 using System.Security.Permissions;
 
-namespace System.Web.UI.WebControls {
-
+namespace System.Web.UI.WebControls
+{
        [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public class CommandField : ButtonFieldBase
@@ -47,7 +46,7 @@ namespace System.Web.UI.WebControls {
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Appearance")]
                public virtual string CancelImageUrl {
-                       get { return ViewState.GetString ("CancelImageUrl", ""); }
+                       get { return ViewState.GetString ("CancelImageUrl", String.Empty); }
                        set {
                                ViewState ["CancelImageUrl"] = value;
                                OnFieldChanged ();
@@ -80,7 +79,7 @@ namespace System.Web.UI.WebControls {
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Appearance")]
                public virtual string DeleteImageUrl {
-                       get { return ViewState.GetString ("DeleteImageUrl", ""); }
+                       get { return ViewState.GetString ("DeleteImageUrl", String.Empty); }
                        set {
                                ViewState ["DeleteImageUrl"] = value;
                                OnFieldChanged ();
@@ -104,7 +103,7 @@ namespace System.Web.UI.WebControls {
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Appearance")]
                public virtual string EditImageUrl {
-                       get { return ViewState.GetString ("EditImageUrl", ""); }
+                       get { return ViewState.GetString ("EditImageUrl", String.Empty); }
                        set {
                                ViewState ["EditImageUrl"] = value;
                                OnFieldChanged ();
@@ -128,7 +127,7 @@ namespace System.Web.UI.WebControls {
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Appearance")]
                public virtual string InsertImageUrl {
-                       get { return ViewState.GetString ("InsertImageUrl", ""); }
+                       get { return ViewState.GetString ("InsertImageUrl", String.Empty); }
                        set {
                                ViewState ["InsertImageUrl"] = value;
                                OnFieldChanged ();
@@ -152,7 +151,7 @@ namespace System.Web.UI.WebControls {
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Appearance")]
                public virtual string NewImageUrl {
-                       get { return ViewState.GetString ("NewImageUrl", ""); }
+                       get { return ViewState.GetString ("NewImageUrl", String.Empty); }
                        set {
                                ViewState ["NewImageUrl"] = value;
                                OnFieldChanged ();
@@ -176,7 +175,7 @@ namespace System.Web.UI.WebControls {
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Appearance")]
                public virtual string SelectImageUrl {
-                       get { return ViewState.GetString ("SelectImageUrl", ""); }
+                       get { return ViewState.GetString ("SelectImageUrl", String.Empty); }
                        set {
                                ViewState ["SelectImageUrl"] = value;
                                OnFieldChanged ();
@@ -255,7 +254,7 @@ namespace System.Web.UI.WebControls {
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Appearance")]
                public virtual string UpdateImageUrl {
-                       get { return ViewState.GetString ("UpdateImageUrl", ""); }
+                       get { return ViewState.GetString ("UpdateImageUrl", String.Empty); }
                        set {
                                ViewState ["UpdateImageUrl"] = value;
                                OnFieldChanged ();
@@ -273,24 +272,26 @@ namespace System.Web.UI.WebControls {
                        }
                }
                
-               public override void InitializeCell (DataControlFieldCell cell,
-                       DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
+               public override void InitializeCell (DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
                {
                        string index = rowIndex.ToString ();
                        
-                       if (cellType == DataControlCellType.DataCell)
-                       {
+                       if (cellType == DataControlCellType.DataCell) {
                                if ((rowState & DataControlRowState.Edit) != 0) {
-                                       cell.Controls.Add (CreateButton (UpdateText, UpdateImageUrl, DataControlCommands.UpdateCommandName, index));
-                                       if (ShowCancelButton) {
-                                               AddSeparator (cell);
-                                               cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
+                                       if (ShowEditButton) {
+                                               cell.Controls.Add (CreateButton (UpdateText, UpdateImageUrl, DataControlCommands.UpdateCommandName, index));
+                                               if (ShowCancelButton) {
+                                                       AddSeparator (cell);
+                                                       cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
+                                               }
                                        }
                                } else if ((rowState & DataControlRowState.Insert) != 0) {
-                                       cell.Controls.Add (CreateButton (InsertText, InsertImageUrl, DataControlCommands.InsertCommandName, index));
-                                       if (ShowCancelButton) {
-                                               AddSeparator (cell);
-                                               cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
+                                       if (ShowInsertButton) {
+                                               cell.Controls.Add (CreateButton (InsertText, InsertImageUrl, DataControlCommands.InsertCommandName, index));
+                                               if (ShowCancelButton) {
+                                                       AddSeparator (cell);
+                                                       cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
+                                               }
                                        }
                                } else {
                                        if (ShowEditButton) {
@@ -314,11 +315,17 @@ namespace System.Web.UI.WebControls {
                                base.InitializeCell (cell, cellType, rowState, rowIndex);
                }
                
-               DataControlButton CreateButton (string text, string image, string command, string arg)
+               Control CreateButton (string text, string image, string command, string arg)
                {
-                       DataControlButton c = new DataControlButton (Control, text, image, command, arg, false);
-                       c.CausesValidation = CausesValidation;
-                       return c;
+                       IDataControlButton c = DataControlButton.CreateButton (ButtonType, Control, text, image, command, arg, false);
+                       if (CausesValidation) {
+                               if (command == DataControlCommands.UpdateCommandName || command == DataControlCommands.InsertCommandName) {
+                                       c.Container = null;
+                                       c.CausesValidation = true;
+                                       c.ValidationGroup = ValidationGroup;
+                               }
+                       }
+                       return (Control)c;
                }
                
                void AddSeparator (DataControlFieldCell cell)
@@ -361,10 +368,10 @@ namespace System.Web.UI.WebControls {
                }
                
                public override void ValidateSupportsCallback ()
-               {\r
-                       if (ShowSelectButton)\r
-                               throw new NotSupportedException ("ShowSelectButton = true");
+               {
+                       if (ShowSelectButton)
+                               throw new NotSupportedException ("Callbacks are not supported on CommandField when the select button is enabled because other controls on your page that are dependent on the selected value of '" + Control.ID + "' for their rendering will not update in a callback.  Turn callbacks off on '" + Control.ID + "'.");
                }
        }
 }
-#endif
+