Browse Source

2010-06-02 Marek Habersack <[email protected]>

	* ViewStateMode.cs: added

	* Control.cs: implemented 4.0 ViewStateMode

svn path=/trunk/mcs/; revision=158368
Marek Habersack 15 years ago
parent
commit
4a49acbd3b

+ 4 - 0
mcs/class/System.Web/System.Web.UI/ChangeLog

@@ -1,5 +1,9 @@
 2010-06-02  Marek Habersack  <[email protected]>
 
+	* ViewStateMode.cs: added
+
+	* Control.cs: implemented 4.0 ViewStateMode
+
 	* Page.cs: implemented 4.0 properties AutoPostBackControl and
 	RouteData
 

+ 26 - 3
mcs/class/System.Web/System.Web.UI/Control.cs

@@ -103,7 +103,9 @@ namespace System.Web.UI
 		TemplateControl _templateControl;
 		bool _isChildControlStateCleared;
 		string _templateSourceDirectory;
-
+#if NET_4_0
+		ViewStateMode viewStateMode;
+#endif
 		/*************/
 		int stateMask;
 		const int ENABLE_VIEWSTATE = 1;
@@ -139,6 +141,9 @@ namespace System.Web.UI
 			stateMask = ENABLE_VIEWSTATE | VISIBLE | AUTOID | BINDING_CONTAINER | AUTO_EVENT_WIREUP;
 			if (this is INamingContainer)
 				stateMask |= IS_NAMING_CONTAINER;
+#if NET_4_0
+			viewStateMode = ViewStateMode.Inherit;
+#endif
 		}
 		
 		ControlAdapter adapter;
@@ -275,10 +280,16 @@ namespace System.Web.UI
 
 		protected internal bool IsViewStateEnabled {
 			get {
-				for (Control control = this; control != null; control = control.Parent)
+				for (Control control = this; control != null; control = control.Parent) {
 					if (!control.EnableViewState)
 						return false;
-
+#if NET_4_0
+					ViewStateMode vsm = control.ViewStateMode;
+					if (vsm != ViewStateMode.Inherit)
+						return vsm == ViewStateMode.Enabled;
+#endif
+				}
+				
 				return true;
 			}
 		}
@@ -1828,6 +1839,18 @@ namespace System.Web.UI
 			}
 		}
 #if NET_4_0
+		[ThemeableAttribute(false)]
+		[DefaultValue ("0")]
+		public virtual ViewStateMode ViewStateMode {
+			get { return viewStateMode;  }
+			set {
+				if (value < ViewStateMode.Inherit || value > ViewStateMode.Disabled)
+					throw new ArgumentOutOfRangeException ("An attempt was made to set this property to a value that is not in the ViewStateMode enumeration.");
+
+				viewStateMode = value;
+			}
+		}
+
 		public string GetRouteUrl (object routeParameters)
 		{
 			return GetRouteUrl (null, new RouteValueDictionary (routeParameters));

+ 8 - 1
mcs/class/System.Web/System.Web.UI/Page.cs

@@ -183,6 +183,9 @@ public partial class Page : TemplateControl, IHttpHandler
 			viewStateEncryptionMode = ViewStateEncryptionMode.Auto;
 			_viewState = true;
 		}
+#if NET_4_0
+		this.ViewStateMode = ViewStateMode.Enabled;
+#endif
 	}
 
 	#endregion		
@@ -1786,7 +1789,11 @@ public partial class Page : TemplateControl, IHttpHandler
 		Pair vsr = null;
 		object viewState = null;
 		
-		if (EnableViewState)
+		if (EnableViewState
+#if NET_4_0
+		    && this.ViewStateMode == ViewStateMode.Enabled
+#endif
+		)
 			viewState = SaveViewStateRecursive ();
 		
 		object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;

+ 36 - 0
mcs/class/System.Web/System.Web.UI/ViewStateMode.cs

@@ -0,0 +1,36 @@
+//
+// Authors:
+//   Marek Habersack <[email protected]>
+//
+// (C) 2010 Novell, Inc (http://novell.com/)
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+namespace System.Web.UI
+{
+	public enum ViewStateMode
+	{
+		Inherit,
+		Enabled,
+		Disabled
+	}
+}

+ 1 - 0
mcs/class/System.Web/net_4_0_System.Web.dll.sources

@@ -17,6 +17,7 @@ System.Web.Compilation/RouteUrlExpressionBuilder.cs
 System.Web.Compilation/RouteValueExpressionBuilder.cs
 System.Web.SessionState_2.0/SessionStateBehavior.cs
 System.Web.Routing/PageRouteHandler.cs
+System.Web.UI/ViewStateMode.cs
 System.Web.UI.WebControls/IDataBoundControl.cs
 System.Web.UI.WebControls/IDataBoundItemControl.cs
 System.Web.UI.WebControls/IDataBoundListControl.cs