2006-09-20 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / ListControl.cs
index 6f80858eb14b80e7695355120b6858822d7502b6..acf4c7c8aefce247336f59936db0335992b6d66a 100644 (file)
@@ -42,11 +42,9 @@ namespace System.Web.UI.WebControls {
        [DefaultPropertyAttribute ("DataSource")]
 #endif
        [Designer("System.Web.UI.Design.WebControls.ListControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
+       [ParseChildrenAttribute (true, "Items")]
 #if NET_2_0
        [ControlValueProperty ("SelectedValue", null)]
-       [ParseChildrenAttribute (true, "Items", ChildControlType = typeof (Control))]
-#else
-       [ParseChildrenAttribute (true, "Items")]
 #endif 
        public abstract class ListControl :
 #if NET_2_0
@@ -196,10 +194,6 @@ namespace System.Web.UI.WebControls {
                                return -1;
                        }
                        set {
-                               ClearSelection ();
-                               if (value == -1)
-                                       return;
-
                                if (items == null || items.Count == 0) {
                                        // This will happen when assigning this property
                                        // before DataBind () is called on the control.
@@ -207,8 +201,13 @@ namespace System.Web.UI.WebControls {
                                        return;
                                }
 
-                               if (value < 0 || value >= Items.Count)
+                               if (value < -1 || value >= Items.Count)
                                        throw new ArgumentOutOfRangeException ("value");
+
+                               ClearSelection ();
+                               if (value == -1)
+                                       return;
+
                                items [value].Selected = true;
 
                                /* you'd think this would be called, but noooo */
@@ -322,30 +321,6 @@ namespace System.Web.UI.WebControls {
                                items [i].Selected = false;
                }
 
-#if NET_2_0
-               protected internal override void LoadControlState (object savedState)
-               {
-                       object first = null;
-                       ArrayList indices = null;
-                       Pair pair = savedState as Pair;
-
-                       if (pair != null) {
-                               first = pair.First;
-                               indices = pair.Second as ArrayList;
-                       }
-
-                       base.LoadControlState (first);
-
-                       if (indices != null) {
-                               int count = Items.Count;
-                               foreach (int index in indices) {
-                                       if (index >= 0 && index < count)
-                                               Items [index].Selected = true;
-                               }
-                       }
-               }
-#endif         
-
                protected override void OnDataBinding (EventArgs e)
                {
                        base.OnDataBinding (e);
@@ -372,14 +347,6 @@ namespace System.Web.UI.WebControls {
                        }
                }
 
-#if NET_2_0
-               protected internal override void OnInit (EventArgs e)
-               {
-                       Page.RegisterRequiresControlState (this);
-                       base.OnInit (e);
-               }
-#endif         
-
 #if NET_2_0
                protected internal
 #else          
@@ -454,18 +421,6 @@ namespace System.Web.UI.WebControls {
                        base.RenderContents (w);
                }
 
-               protected internal override object SaveControlState ()
-               {
-                       object first;
-                       ArrayList second;
-
-                       first = base.SaveControlState ();
-                       second = GetSelectedIndicesInternal ();
-                       if (second == null)
-                               second = new ArrayList();
-
-                       return new Pair (first, second);
-               }
 #endif         
 
                internal ArrayList GetSelectedIndicesInternal ()
@@ -493,46 +448,26 @@ namespace System.Web.UI.WebControls {
                        if (manager != null)
                                second = manager.SaveViewState ();
 
-#if !NET_2_0
                        ArrayList selected = GetSelectedIndicesInternal ();
-#endif
 
-                       if (first == null && second == null
-#if !NET_2_0
-                           && selected == null
-#endif
-                           )
+                       if (first == null && second == null && selected == null)
                                return null;
 
-#if NET_2_0
-                       return new Pair (first, second);
-#else
                        return new Triplet (first, second, selected);
-#endif
                }
 
                protected override void LoadViewState (object savedState)
                {
                        object first = null;
                        object second = null;
-#if !NET_2_0
                        ArrayList indices = null;
-#endif
 
-#if NET_2_0
-                       Pair pair = savedState as Pair;
-                       if (pair != null) {
-                               first = pair.First;
-                               second = pair.Second;
-                       }
-#else
                        Triplet triplet = savedState as Triplet;
                        if (triplet != null) {
                                first = triplet.First;
                                second = triplet.Second;
                                indices = triplet.Third as ArrayList;
                        }
-#endif
 
                        base.LoadViewState (first);
 
@@ -541,12 +476,10 @@ namespace System.Web.UI.WebControls {
                                manager.LoadViewState (second);
                        }
 
-#if !NET_2_0
                        if (indices != null) {
                                foreach (int index in indices)
                                        Items [index].Selected = true;
                        }
-#endif
                }
 
 #if NET_2_0
@@ -597,31 +530,30 @@ namespace System.Web.UI.WebControls {
                }
                
                
-               [MonoTODO]
                [Themeable (false)]
                [DefaultValue (false)]
                [WebSysDescription ("")]
                [WebCategory ("Behavior")]
-               public virtual bool CausesValidation {
+               public virtual bool CausesValidation {
                        get {
-                               throw new NotImplementedException ();
+                               return ViewState.GetBool ("CausesValidation", false);
                        }
+
                        set {
-                               throw new NotImplementedException ();   
+                               ViewState ["CausesValidation"] = value;
                        }
                }
 
-               [MonoTODO]
                [Themeable (false)]
                [DefaultValue ("")]
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Behavior")]
                public virtual string ValidationGroup {
                        get {
-                               throw new NotImplementedException ();
+                               return ViewState.GetString ("ValidationGroup", "");
                        }
                        set {
-                               throw new NotImplementedException ();
+                               ViewState ["ValidationGroup"] = value;
                        }
                }