소스 검색

fixed LoadViewState() and SaveViewState() in WebControl.
Before the change the Enabled property wasn't updated when a postback
event was raised.
fixed SelectedIndex property implementation in ListControl.
Prevents throwing ArgumentOutOfRangeException (that should not be thrown),
when the list is empty.

svn path=/trunk/mcs/; revision=26817

Alon Gazit 21 년 전
부모
커밋
6eb1ccb667

+ 8 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,11 @@
+2004-05-06 Alon Gazit <[email protected]>
+        * WebControl.cs: fixed LoadViewState() and SaveViewState(). 
+        Before the change the Enabled property wasn't updated when a postback
+        event was raised.
+        * ListControl.cs: fixed SelectedIndex property implementation.
+        Prevents throwing ArgumentOutOfRangeException (that should not be thrown),
+        when the list is empty.     
+
 2004-04-28 Alon Gazit <[email protected]>
         * WebControl.cs: fixed LoadViewState(). 
         Always loading the saved attributes collection.

+ 6 - 1
mcs/class/System.Web/System.Web.UI.WebControls/ListControl.cs

@@ -209,7 +209,12 @@ namespace System.Web.UI.WebControls
 				return -1;
 			}
 			set {
-				if (value < -1 || value > Items.Count)
+				if (Items.Count == 0)
+				{
+					cachedSelectedIndex = value;
+					return;
+				}
+				if ((value < -1) || (value >= Items.Count))
 					throw new ArgumentOutOfRangeException ();
 
 				ClearSelection ();

+ 10 - 1
mcs/class/System.Web/System.Web.UI.WebControls/WebControl.cs

@@ -432,6 +432,13 @@ namespace System.Web.UI.WebControls
 				attributeState = new StateBag(true);
 				attributeState.TrackViewState();
 				attributeState.LoadViewState (saved.Second);
+			}
+			
+			object enable = ViewState["Enabled"];
+			if (enable!=null)
+			{
+				Enabled = (bool)enable;
+				EnableViewState = true; 
 			}
 		}
 
@@ -448,7 +455,9 @@ namespace System.Web.UI.WebControls
 		}
 
 		protected override object SaveViewState()
-		{
+		{
+			if (EnableViewState)
+				ViewState["Enabled"] = enabled;
 			if (ControlStyleCreated)
 				ControlStyle.SaveViewState ();