Author: igorz
Date: 2006-11-08 07:57:58 -0500 (Wed, 08 Nov 2006)
New Revision: 67514
Modified:
trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
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-09 Igor Zelmanovich <[EMAIL PROTECTED]>
* Page.cs: fixed: LoadControlState is called for controls
that added on Load and latter, for 1.x refactoring only
Modified: trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/ChangeLog 2006-11-08 12:35:48 UTC
(rev 67513)
+++ trunk/mcs/class/System.Web/System.Web.UI/ChangeLog 2006-11-08 12:57:58 UTC
(rev 67514)
@@ -1,3 +1,8 @@
+2006-11-09 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+ * Page.cs: fixed: LoadControlState is called for controls
+ that added on Load and latter, for 1.x refactoring only
+
2006-11-02 Igor Zelmanovich <[EMAIL PROTECTED]>
* ClientScriptManager.cs:
Modified: trunk/mcs/class/System.Web/System.Web.UI/Page.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/Page.cs 2006-11-08 12:35:48 UTC
(rev 67513)
+++ trunk/mcs/class/System.Web/System.Web.UI/Page.cs 2006-11-08 12:57:58 UTC
(rev 67514)
@@ -1118,6 +1118,7 @@
void InternalProcessRequest ()
{
_requestValueCollection = this.DeterminePostBackMode();
+ LoadPageStateFromPersistenceMedium ();
#if NET_2_0
// http://msdn2.microsoft.com/en-us/library/ms178141.aspx
@@ -1383,22 +1384,16 @@
internal void LoadPageViewState()
{
- object sState = LoadPageStateFromPersistenceMedium ();
- if (sState != null) {
+ if (_savedViewState != null) {
#if NET_2_0
- Triplet data = (Triplet) sState;
+ Triplet data = (Triplet) _savedViewState;
+#else
+ Pair data = (Pair) _savedViewState;
+#endif
if (allow_load) {
- LoadPageControlState (data.Third);
LoadViewStateRecursive (data.First);
_requiresPostBack = data.Second as ArrayList;
}
-#else
- Pair pair = (Pair) sState;
- if (allow_load) {
- LoadViewStateRecursive (pair.First);
- _requiresPostBack = pair.Second as ArrayList;
- }
-#endif
}
}
@@ -1737,8 +1732,25 @@
[EditorBrowsable (EditorBrowsableState.Advanced)]
public void RegisterRequiresControlState (Control control)
{
+ if (control == null)
+ throw new ArgumentNullException ("control");
+
+ if (RequiresControlState (control))
+ return;
+
if (requireStateControls == null) requireStateControls = new
ArrayList ();
- requireStateControls.Add (control);
+ int n = requireStateControls.Add (control);
+
+ if (IsPostBack || IsCallback) {
+ if (_savedViewState != null) {
+ object [] states = (object []) ((Triplet)
_savedViewState).Third;
+ if (states != null && n < states.Length) {
+ object state = states [n];
+ if (state != null)
+ control.LoadControlState
(state);
+ }
+ }
+ }
}
public bool RequiresControlState (Control control)
@@ -1792,19 +1804,7 @@
if (allNull) return null;
else return state;
}
-
- void LoadPageControlState (object data)
- {
- if (requireStateControls == null) return;
- object[] state = (object[]) data;
- int max = Math.Min (requireStateControls.Count, state != null ?
state.Length : requireStateControls.Count);
- for (int n=0; n < max; n++) {
- Control ctl = (Control) requireStateControls [n];
- ctl.LoadControlState (state != null ? state [n] : null);
- }
- }
-
void LoadPreviousPageReference ()
{
if (_requestValueCollection != null) {
Modified: trunk/mcs/class/System.Web/Test/System.Web.UI/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI/ChangeLog 2006-11-08
12:35:48 UTC (rev 67513)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI/ChangeLog 2006-11-08
12:57:58 UTC (rev 67514)
@@ -1,3 +1,7 @@
+2006-11-09 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+ * ControlTest.cs: added test.
+
2006-11-02 Igor Zelmanovich <[EMAIL PROTECTED]>
* ClientScriptManagerTest.cs: removed NotWorking attributes, fixed
tests.
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-08 12:35:48 UTC (rev 67513)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI/ControlTest.cs
2006-11-08 12:57:58 UTC (rev 67514)
@@ -38,6 +38,7 @@
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
+using MonoTests.SystemWeb.Framework;
namespace MonoTests.System.Web.UI
{
@@ -176,6 +177,61 @@
p.EnableViewState = false;
Assert.IsFalse (c.DoIsViewStateEnabled);
}
+
+ [Test]
+ [Category ("NunitWeb")]
+ public void ControlState () {
+ WebTest t = new WebTest (PageInvoker.CreateOnLoad
(ControlState_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 ();
+ }
+
+ public static void ControlState_Load (Page p) {
+ ControlWithState c1 = new ControlWithState ();
+ ControlWithState c2 = new ControlWithState ();
+ c1.Controls.Add (c2);
+ p.Form.Controls.Add (c1);
+ if (!p.IsPostBack) {
+ c1.State = "State";
+ c2.State = "Cool";
+ }
+ else {
+ ControlWithState c3 = new ControlWithState ();
+ p.Form.Controls.Add (c3);
+ Assert.AreEqual ("State", c1.State,
"ControlState");
+ Assert.AreEqual ("Cool", c2.State,
"ControlState");
+ }
+ }
+
+ class ControlWithState : 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 object SaveControlState () {
+ return State;
+ }
+
+ protected override void LoadControlState (object
savedState) {
+ State = (string) savedState;
+ }
+ }
#endif
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches