Author: igorz
Date: 2006-11-26 10:34:53 -0500 (Sun, 26 Nov 2006)
New Revision: 68477
Modified:
trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
trunk/mcs/class/System.Web/System.Web.UI/Control.cs
trunk/mcs/class/System.Web/System.Web.UI/Page.cs
trunk/mcs/class/System.Web/Test/System.Web.UI/ChangeLog
trunk/mcs/class/System.Web/Test/System.Web.UI/ControlTest.cs
Log:
2006-11-26 Igor Zelmanovich <[EMAIL PROTECTED]>
* Page.cs:
* Control.cs:
implemented ClearChildState(), ClearChildControlState() and
IsChildControlStateCleared
Modified: trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/ChangeLog 2006-11-26 14:33:42 UTC
(rev 68476)
+++ trunk/mcs/class/System.Web/System.Web.UI/ChangeLog 2006-11-26 15:34:53 UTC
(rev 68477)
@@ -1,6 +1,13 @@
2006-11-26 Igor Zelmanovich <[EMAIL PROTECTED]>
* Page.cs:
+ * Control.cs:
+ implemented ClearChildState(), ClearChildControlState() and
+ IsChildControlStateCleared
+
+2006-11-26 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+ * Page.cs:
* ClientScriptManager.cs:
implemented RegisterExpandoAttribute feature
Modified: trunk/mcs/class/System.Web/System.Web.UI/Control.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/Control.cs 2006-11-26 14:33:42 UTC
(rev 68476)
+++ trunk/mcs/class/System.Web/System.Web.UI/Control.cs 2006-11-26 15:34:53 UTC
(rev 68477)
@@ -106,6 +106,9 @@
Hashtable pendingVS; // may hold unused viewstate data from
child controls
+#if NET_2_0
+ bool _isChildControlStateCleared;
+#endif
/*************/
int stateMask;
const int ENABLE_VIEWSTATE = 1;
@@ -269,11 +272,8 @@
}
}
- protected internal bool IsChildControlStateCleared
- {
- get {
- throw new NotImplementedException ();
- }
+ protected internal bool IsChildControlStateCleared {
+ get { return _isChildControlStateCleared; }
}
protected internal bool IsViewStateEnabled
@@ -622,12 +622,13 @@
#if NET_2_0
protected void ClearChildControlState ()
{
- throw new NotImplementedException ();
+ _isChildControlStateCleared = true;
}
protected void ClearChildState ()
{
- throw new NotImplementedException ();
+ ClearChildViewState ();
+ ClearChildControlState ();
}
#endif
Modified: trunk/mcs/class/System.Web/System.Web.UI/Page.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/Page.cs 2006-11-26 14:33:42 UTC
(rev 68476)
+++ trunk/mcs/class/System.Web/System.Web.UI/Page.cs 2006-11-26 15:34:53 UTC
(rev 68477)
@@ -1851,11 +1851,16 @@
requireStateControls = new ArrayList ();
int n = requireStateControls.Add (control);
- if (_savedControlState != null && n <
_savedControlState.Length) {
- object state = _savedControlState [n];
- if (state != null)
- control.LoadControlState (state);
- }
+ if (_savedControlState == null || n >=
_savedControlState.Length)
+ return;
+
+ for (Control parent = control.Parent; parent != null; parent =
parent.Parent)
+ if (parent.IsChildControlStateCleared)
+ return;
+
+ object state = _savedControlState [n];
+ if (state != null)
+ control.LoadControlState (state);
}
public bool RequiresControlState (Control control)
Modified: trunk/mcs/class/System.Web/Test/System.Web.UI/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI/ChangeLog 2006-11-26
14:33:42 UTC (rev 68476)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI/ChangeLog 2006-11-26
15:34:53 UTC (rev 68477)
@@ -1,5 +1,9 @@
2006-11-26 Igor Zelmanovich <[EMAIL PROTECTED]>
+ * ControlTest.cs: removed NotWorking attributes, fixed tests.
+
+2006-11-26 Igor Zelmanovich <[EMAIL PROTECTED]>
+
* ClientScriptManagerTest.cs: removed NotWorking attributes.
2006-11-22 Igor Zelmanovich <[EMAIL PROTECTED]>
Modified: trunk/mcs/class/System.Web/Test/System.Web.UI/ControlTest.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI/ControlTest.cs
2006-11-26 14:33:42 UTC (rev 68476)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI/ControlTest.cs
2006-11-26 15:34:53 UTC (rev 68477)
@@ -185,7 +185,6 @@
}
[Test]
- [Category ("NotWorking")]
[Category ("NunitWeb")]
public void ClearChildControlState ()
{
@@ -201,23 +200,28 @@
}
public static void ClearChildControlState_Load (Page p)
{
- ParentControlWithState c1 = new ParentControlWithState
();
+ ControlWithState c1 = new ControlWithState ();
+ p.Form.Controls.Add (c1);
+ if (p.IsPostBack) {
+ c1.ClearChildControlState ();
+ }
ControlWithState c2 = new ControlWithState ();
c1.Controls.Add (c2);
- p.Form.Controls.Add (c1);
+ ControlWithState c3 = new ControlWithState ();
+ c2.Controls.Add (c3);
if (!p.IsPostBack) {
c1.State = "State";
c2.State = "Cool";
+ c3.State = "SubCool";
}
else {
- c1.ClearChildControlState ();
Assert.AreEqual ("State", c1.State,
"ControlState#1");
Assert.AreEqual (null, c2.State,
"ControlState#2");
+ Assert.AreEqual (null, c3.State,
"ControlState#2");
}
}
[Test]
- [Category ("NotWorking")]
[Category ("NunitWeb")]
public void ClearChildState ()
{
@@ -233,21 +237,28 @@
}
public static void ClearChildState_Load (Page p)
{
- ParentControlWithViewState c1 = new
ParentControlWithViewState ();
- ParentControlWithViewState c2 = new
ParentControlWithViewState ();
- c1.Controls.Add (c2);
+ ControlWithState c1 = new ControlWithState ();
p.Form.Controls.Add (c1);
+ if (p.IsPostBack) {
+ c1.ClearChildState ();
+ }
+ ControlWithState c2 = new ControlWithState ();
+ c1.Controls.Add (c2);
+ ControlWithState c3 = new ControlWithState ();
+ c2.Controls.Add (c3);
if (!p.IsPostBack) {
c1.State = "State";
c2.State = "Cool";
- c1.Viewstate = "VState";
- c2.Viewstate = "VCool";
+ c2.Viewstate = "Very Cool";
+ c3.State = "SubCool";
+ c3.Viewstate = "Super Cool";
}
else {
- Assert.AreEqual ("State", c1.State,
"ControlState#1");
- Assert.AreEqual ("VState", c1.Viewstate,
"ControlViewState#1");
- Assert.AreEqual (null, c2.State,
"ControlState#2");
- Assert.AreEqual (null, c2.Viewstate,
"ControlViewState#2");
+ Assert.AreEqual ("State", c1.State,
"ClearChildState#1");
+ Assert.AreEqual (null, c2.State,
"ClearChildState#2");
+ Assert.AreEqual (null, c3.State,
"ClearChildState#3");
+ Assert.AreEqual (null, c2.Viewstate,
"ClearChildState#4");
+ Assert.AreEqual (null, c3.Viewstate,
"ClearChildState#5");
}
}
@@ -401,6 +412,67 @@
}
[Test]
+ [Category ("NunitWeb")]
+ public void ControlState2 () {
+ WebTest t = new WebTest (PageInvoker.CreateOnLoad
(ControlState2_Load));
+ t.Run ();
+ FormRequest fr = new FormRequest (t.Response, "form1");
+ fr.Controls.Add ("__EVENTTARGET");
+ fr.Controls.Add ("__EVENTARGUMENT");
+ fr.Controls ["__EVENTTARGET"].Value = "";
+ fr.Controls ["__EVENTARGUMENT"].Value = "";
+ t.Request = fr;
+ t.Run ();
+
+ fr = new FormRequest (t.Response, "form1");
+ fr.Controls.Add ("__EVENTTARGET");
+ fr.Controls.Add ("__EVENTARGUMENT");
+ fr.Controls ["__EVENTTARGET"].Value = "";
+ fr.Controls ["__EVENTARGUMENT"].Value = "";
+ t.Request = fr;
+ t.Run ();
+ }
+ public static void ControlState2_Load (Page p) {
+ ControlWithState parent = new ControlWithState ();
+ p.Form.Controls.Add (parent);
+ if (!p.IsPostBack) {
+ // emulate DataBind
+ parent.Controls.Clear ();
+ parent.ClearChildControlState ();
+ ControlWithState c1 = new ControlWithState ();
+ ControlWithState c2 = new ControlWithState ();
+ parent.Controls.Add (c1);
+ parent.Controls.Add (c2);
+ c1.State = "State1_1";
+ c2.State = "State1_2";
+ parent.State = "First";
+ }
+ else if (parent.State == "First") {
+ // emulate DataBind
+ parent.Controls.Clear ();
+ parent.ClearChildControlState ();
+ ControlWithState c1 = new ControlWithState ();
+ ControlWithState c2 = new ControlWithState ();
+ parent.Controls.Add (c1);
+ parent.Controls.Add (c2);
+ c1.State = "State2_1";
+ c2.State = "State2_2";
+ parent.State = "Second";
+ }
+ else {
+ // emulate CrerateChildControl only
+ parent.Controls.Clear ();
+ ControlWithState c1 = new ControlWithState ();
+ ControlWithState c2 = new ControlWithState ();
+ parent.Controls.Add (c1);
+ parent.Controls.Add (c2);
+
+ Assert.AreEqual ("State2_1", c1.State,
"ControlState#1");
+ Assert.AreEqual ("State2_2", c2.State,
"ControlState#2");
+ }
+ }
+
+ [Test]
public void ClientIDSeparator ()
{
DerivedControl ctrl = new DerivedControl ();
@@ -416,7 +488,6 @@
[Test]
[Category ("NunitWeb")]
- [Category ("NotWorking")]
public void IsChildControlStateCleared ()
{
WebTest t = new WebTest (PageInvoker.CreateOnLoad
(IsChildControlStateCleared_Load));
@@ -431,27 +502,33 @@
}
public static void IsChildControlStateCleared_Load (Page p)
{
- ParentControlWithState c1 = new ParentControlWithState
();
+ ControlWithState c1 = new ControlWithState ();
+ p.Form.Controls.Add (c1);
+ if (p.IsPostBack) {
+ Assert.IsFalse (c1.IsChildControlStateCleared,
"ControlState#1");
+ c1.ClearChildControlState ();
+ Assert.IsTrue (c1.IsChildControlStateCleared,
"ControlState#1");
+ }
ControlWithState c2 = new ControlWithState ();
c1.Controls.Add (c2);
- p.Form.Controls.Add (c1);
+ ControlWithState c3 = new ControlWithState ();
+ c2.Controls.Add (c3);
+ if (p.IsPostBack) {
+ Assert.IsFalse (c2.IsChildControlStateCleared,
"ControlState#1");
+ Assert.IsFalse (c3.IsChildControlStateCleared,
"ControlState#1");
+ }
if (!p.IsPostBack) {
c1.State = "State";
c2.State = "Cool";
+ c3.State = "SubCool";
}
- else {
- c1.ClearChildControlState ();
- Assert.AreEqual ("State", c1.State,
"ControlState#1");
- Assert.AreEqual (null, c2.State,
"ControlState#2");
- Assert.AreEqual (true,
c1.IsChildControlStateCleared, "IsChildControlStateCleared");
- }
}
[Test]
[Category ("NunitWeb")]
public void LoadViewStateByID ()
{
- ParentControlWithState c1 = new ParentControlWithState
();
+ ControlWithState c1 = new ControlWithState ();
ControlWithState c2 = new ControlWithState ();
c1.Controls.Add (c2);
Assert.AreEqual (false, c1.LoadViewStateByID,
"LoadViewStateByID#1");
@@ -607,11 +684,15 @@
set { _state = value; }
}
+ public string Viewstate {
+ get { return (string) ViewState ["Viewstate"]; }
+ set { ViewState ["Viewstate"] = value; }
+ }
+
protected override void OnInit (EventArgs e)
{
base.OnInit (e);
Page.RegisterRequiresControlState (this);
- Page.RegisterRequiresControlState (this);
}
protected override object SaveControlState ()
@@ -624,45 +705,11 @@
State = (string) savedState;
}
- public new void ClearChildControlState ()
+ public new void ClearChildState ()
{
- base.ClearChildControlState ();
+ base.ClearChildState ();
}
- }
- class ParentControlWithState : Control
- {
- string _state;
- public string State
- {
- get { return _state; }
- set { _state = value; }
- }
-
- protected override void OnInit (EventArgs e)
- {
- base.OnInit (e);
- Page.RegisterRequiresControlState (this);
- Page.RegisterRequiresControlState (this);
- }
-
- protected override void CreateChildControls ()
- {
- Controls.Clear ();
- base.CreateChildControls ();
- ClearChildControlState ();
- }
-
- protected override object SaveControlState ()
- {
- return State;
- }
-
- protected override void LoadControlState (object
savedState)
- {
- State = (string) savedState;
- }
-
public new void ClearChildControlState ()
{
base.ClearChildControlState ();
@@ -679,61 +726,6 @@
}
}
- class ParentControlWithViewState : Control
- {
-
- string _viewstate;
- public string Viewstate
- {
- get { return _viewstate; }
- set { _viewstate = value; }
- }
- string _state;
- public string State
- {
- get { return _state; }
- set { _state = value; }
- }
-
- protected override void OnInit (EventArgs e)
- {
- base.OnInit (e);
- Page.RegisterRequiresControlState (this);
- Page.RegisterRequiresControlState (this);
- }
-
- protected override void CreateChildControls ()
- {
- Controls.Clear ();
- base.CreateChildControls ();
- ClearChildControlState ();
- }
-
- protected override object SaveViewState ()
- {
- return Viewstate;
- }
-
- protected override void LoadViewState (object
savedState)
- {
- Viewstate = (string) savedState;
- }
-
- protected override object SaveControlState ()
- {
- return State;
- }
-
- protected override void LoadControlState (object
savedState)
- {
- State = (string) savedState;
- }
-
- public new void ClearChildControlState ()
- {
- base.ClearChildControlState ();
- }
- }
#endif
class MyNC : Control, INamingContainer
{
@@ -856,3 +848,4 @@
}
+
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches