2007-08-06 Igor Zelmanovich <igorz@mainsoft.com>
authorIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Mon, 6 Aug 2007 14:45:58 +0000 (14:45 -0000)
committerIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Mon, 6 Aug 2007 14:45:58 +0000 (14:45 -0000)
* Control.cs: fixed: control ID management.

2007-08-06 Igor Zelmanovich <igorz@mainsoft.com>

* ControlTest.cs:
Added new tests.

2007-08-06 Igor Zelmanovich <igorz@mainsoft.com>

* DataGridTest.cs:
* DetailsViewTest.cs:
fixed tests.

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

mcs/class/System.Web/System.Web.UI/ChangeLog
mcs/class/System.Web/System.Web.UI/Control.cs
mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/Test/System.Web.UI.WebControls/DataGridTest.cs
mcs/class/System.Web/Test/System.Web.UI.WebControls/DetailsViewTest.cs
mcs/class/System.Web/Test/System.Web.UI/ChangeLog
mcs/class/System.Web/Test/System.Web.UI/ControlTest.cs

index 4491c3a1223c30b94ea96a328ebf5670d9ba4600..18e1a369028a829d4f8d0f47df0c1ef3d62f43e7 100644 (file)
@@ -1,3 +1,7 @@
+2007-08-06 Igor Zelmanovich <igorz@mainsoft.com>
+
+       * Control.cs: fixed: control ID management.                     
+
 2007-08-06 Igor Zelmanovich <igorz@mainsoft.com>
 
        * Control.cs: refactoring: code formatting only.                
index 57549ff5f823d6363171985a6d2ed7bdc5dfed0b..a5b14f4404623f5017d5940d8da8ff8e7da5bdd4 100644 (file)
@@ -133,6 +133,7 @@ namespace System.Web.UI
 #if NET_2_0
                const int ENABLE_THEMING = 1 << 16;
 #endif
+               const int AUTOID_SET = 1 << 17;
                /*************/
 
                static Control () {
@@ -345,8 +346,12 @@ namespace System.Web.UI
                public virtual Page Page //DIT
                                {
                        get {
-                               if (_page == null && _parent != null)
-                                       _page = _parent.Page;
+                               if (_page == null){
+                                       if (NamingContainer != null)
+                                               _page = NamingContainer.Page;
+                                       else if (Parent != null)
+                                               _page = Parent.Page;
+                               }
                                return _page;
                        }
                        set {
@@ -465,24 +470,19 @@ namespace System.Web.UI
                                if (uniqueID != null)
                                        return uniqueID;
 
-                               if (_namingContainer == null) {
-                                       if ((stateMask & IS_NAMING_CONTAINER) == 0)
-                                               _namingContainer = NamingContainer;
-                                       if (_namingContainer == null)
-                                               return _userId;
-                               }
+                               if (NamingContainer == null)
+                                       return _userId;
 
-                               if (_userId == null)
-                                       _userId = _namingContainer.GetDefaultName ();
+                               EnsureIDInternal ();
 
-                               string prefix = _namingContainer.UniqueID;
+                               string prefix = NamingContainer.UniqueID;
 #if TARGET_J2EE
                                // For J2EE portlets we need to add the namespace to the ID.
-                               if (_namingContainer == _page && _page.PortletNamespace != null)
-                                       prefix = _page.PortletNamespace;
+                               if (NamingContainer == Page && Page.PortletNamespace != null)
+                                       prefix = Page.PortletNamespace;
                                else
 #endif
-                               if (_namingContainer == _page || prefix == null) {
+                               if (NamingContainer == Page || prefix == null) {
                                        uniqueID = _userId;
                                        return uniqueID;
                                }
@@ -630,8 +630,8 @@ namespace System.Web.UI
                        if (!HasControls ())
                                return;
 
-                       foreach (Control c in _controls)
-                               c.NullifyUniqueID ();
+                       for (int i = 0; i < _controls.Count; i++)
+                               _controls [i].NullifyUniqueID ();
                }
 
                protected internal virtual void AddedControl (Control control, int index) {
@@ -640,17 +640,14 @@ namespace System.Web.UI
                                control._parent.Controls.Remove (control);
 
                        control._parent = this;
-                       control._page = _page;
                        Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
 
-                       if (nc != null) {
-                               control._namingContainer = nc;
-                               if (control.AutoID == true && control._userId == null)
-                                       control._userId = nc.GetDefaultName ();
-                       }
-
                        if ((stateMask & (INITING | INITED)) != 0)
                                control.InitRecursive (nc);
+                       else {
+                               control.SetNamingContainer (nc);
+                               return;
+                       }
 
                        if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
                                if (pendingVS != null) {
@@ -671,6 +668,14 @@ namespace System.Web.UI
                        if ((stateMask & PRERENDERED) != 0)
                                control.PreRenderRecursiveInternal ();
                }
+               
+               void SetNamingContainer (Control nc) {
+                       if (nc != null) {
+                               _namingContainer = nc;
+                               if (AutoID)
+                                       EnsureIDInternal ();
+                       }
+               }
 
                protected virtual void AddParsedSubObject (object obj) //DIT
                {
@@ -739,12 +744,20 @@ namespace System.Web.UI
                        }
                }
 
+               void EnsureIDInternal () {
+                       if (_userId != null)
+                               return;
+
+                       _userId = NamingContainer.GetDefaultName ();
+                       SetMask (AUTOID_SET, true);
+               }
+
 #if NET_2_0
                protected void EnsureID () {
-                       if (Page == null)
+                       if (NamingContainer == null)
                                return;
-                       if (String.IsNullOrEmpty (ID))
-                               ID = NamingContainer.GetDefaultName ();
+                       EnsureIDInternal ();
+                       SetMask (ID_SET, true);
                }
 
                protected bool HasEvents () {
@@ -1405,22 +1418,15 @@ namespace System.Web.UI
                                trace.Write ("control", String.Format ("InitRecursive {0} {1}", _userId, type_name));
                        }
 #endif
+                       SetNamingContainer (namingContainer);
+
                        if (HasControls ()) {
                                if ((stateMask & IS_NAMING_CONTAINER) != 0)
                                        namingContainer = this;
 
-                               if (namingContainer != null &&
-                                       namingContainer._userId == null &&
-                                       namingContainer.AutoID)
-                                       namingContainer._userId = namingContainer.GetDefaultName () + "b";
-
                                int len = _controls.Count;
                                for (int i = 0; i < len; i++) {
                                        Control c = _controls [i];
-                                       c._page = Page;
-                                       c._namingContainer = namingContainer;
-                                       if (namingContainer != null && c._userId == null && c.AutoID)
-                                               c._userId = namingContainer.GetDefaultName () + "c";
                                        c.InitRecursive (namingContainer);
                                }
                        }
@@ -1580,6 +1586,11 @@ namespace System.Web.UI
                        control._parent = null;
                        control._page = null;
                        control._namingContainer = null;
+                       if ((control.stateMask & AUTOID_SET) != 0) {
+                               control._userId = null;
+                               control.SetMask (ID_SET, false);
+                       }
+                       control.NullifyUniqueID ();
                }
 
 
index 4ebf33e114a6b584c80d3e1abf4f776b13d4bf02..47a5573113cb35458cbba6655fa6ef6f9b40c4d7 100644 (file)
@@ -1,3 +1,9 @@
+2007-08-06 Igor Zelmanovich <igorz@mainsoft.com>
+
+       * DataGridTest.cs:
+       * DetailsViewTest.cs:
+       fixed tests.
+
 2007-07-01 Igor Zelmanovich <igorz@mainsoft.com>
 
        * GridViewTest.cs:
index 92b11868556853dbf8003da7bd810543f0e0c083..3dd2d340d03ca89e2f4c9797b9fa63b27334a636 100644 (file)
@@ -1637,7 +1637,7 @@ namespace MonoTests.System.Web.UI.WebControls {
 #if DOT_NET
                        fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl09$ctl01"; 
 #else
-                       fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl08$ctl01c";
+                       fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl08$ctl01";
 #endif
                        fr.Controls ["__EVENTARGUMENT"].Value = "";
                        t.Request = fr;
@@ -1671,7 +1671,7 @@ namespace MonoTests.System.Web.UI.WebControls {
 #if DOT_NET
                        fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl09$ctl00"; 
 #else
-                       fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl08$ctl00c";
+                       fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl08$ctl00";
 #endif
                        fr.Controls ["__EVENTARGUMENT"].Value = "";
                        t.Request = fr;
@@ -1718,7 +1718,7 @@ namespace MonoTests.System.Web.UI.WebControls {
 #if DOT_NET
                        fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl03$ctl00";
 #else
-                       fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl02$ctl00c";
+                       fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl02$ctl00";
 #endif
                        fr.Controls ["__EVENTARGUMENT"].Value = "";
                        t.Request = fr;
@@ -1752,15 +1752,15 @@ namespace MonoTests.System.Web.UI.WebControls {
 #if DOT_NET
                        fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl03$ctl01";
 #else
-                       fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl02$ctl01c";
+                       fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl02$ctl01";
 #endif
                        fr.Controls ["__EVENTARGUMENT"].Value = "";
 #if DOT_NET
                        fr.Controls.Add ("DataGrid1$ctl03$ctl00");
                        fr.Controls ["DataGrid1$ctl03$ctl00"].Value = "New Value";
 #else
-                       fr.Controls.Add ("DataGrid1$ctl02$ctl00c");
-                       fr.Controls ["DataGrid1$ctl02$ctl00c"].Value = "New Value";
+                       fr.Controls.Add ("DataGrid1$ctl02$ctl00");
+                       fr.Controls ["DataGrid1$ctl02$ctl00"].Value = "New Value";
 #endif
                        t.Request = fr;
 
@@ -1795,7 +1795,7 @@ namespace MonoTests.System.Web.UI.WebControls {
 #if DOT_NET
                        fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl04$ctl01";
 #else
-                       fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl03$ctl01c";
+                       fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl03$ctl01";
 #endif
                        fr.Controls ["__EVENTARGUMENT"].Value = "";
                        t.Request = fr;
index a2a9a8f471df846c0a411292cf1ce8b237a47eca..8763790df98a5657a7a7a96ac0b60b56a2008466 100644 (file)
@@ -1946,7 +1946,7 @@ namespace MonoTests.System.Web.UI.WebControls
                        HtmlDiff.AssertAreEqual (origHtmlValue, pageHTML, "InsertDataPostback");\r
                        \r
                        fr = new FormRequest (t.Response, "form1");\r
-#if DOT_NET\r
+\r
                        fr.Controls.Add ("__EVENTTARGET");\r
                        fr.Controls.Add ("__EVENTARGUMENT");\r
                        fr.Controls.Add ("DetailsView1$ctl01");\r
@@ -1958,19 +1958,7 @@ namespace MonoTests.System.Web.UI.WebControls
                        fr.Controls["DetailsView1$ctl01"].Value = "123";\r
                        fr.Controls["DetailsView1$ctl02"].Value = "123";\r
                        fr.Controls["DetailsView1$ctl03"].Value = "123";\r
-#else\r
-                       fr.Controls.Add ("__EVENTTARGET");\r
-                       fr.Controls.Add ("__EVENTARGUMENT");\r
-                       fr.Controls.Add ("DetailsView1$ctl01c");\r
-                       fr.Controls.Add ("DetailsView1$ctl02c");\r
-                       fr.Controls.Add ("DetailsView1$ctl03c");\r
 \r
-                       fr.Controls ["__EVENTTARGET"].Value = "DetailsView1$ctl04c";\r
-                       fr.Controls["__EVENTARGUMENT"].Value = "";\r
-                       fr.Controls ["DetailsView1$ctl01c"].Value = "123";\r
-                       fr.Controls ["DetailsView1$ctl02c"].Value = "123";\r
-                       fr.Controls ["DetailsView1$ctl03c"].Value = "123";\r
-#endif\r
                        t.Request = fr;\r
                        pageHTML = t.Run ();\r
 \r
@@ -2106,7 +2094,7 @@ namespace MonoTests.System.Web.UI.WebControls
                        pageHTML = t.Run ();\r
                        \r
                        fr = new FormRequest (t.Response, "form1");\r
-#if DOT_NET\r
+\r
                        fr.Controls.Add ("__EVENTTARGET");\r
                        fr.Controls.Add ("__EVENTARGUMENT");\r
                        fr.Controls.Add ("DetailsView1$ctl01");\r
@@ -2116,17 +2104,7 @@ namespace MonoTests.System.Web.UI.WebControls
                        fr.Controls["__EVENTARGUMENT"].Value = "";\r
                        fr.Controls["DetailsView1$ctl01"].Value = "1";\r
                        fr.Controls["DetailsView1$ctl02"].Value = "2";\r
-#else\r
-                       fr.Controls.Add ("__EVENTTARGET");\r
-                       fr.Controls.Add ("__EVENTARGUMENT");\r
-                       fr.Controls.Add ("DetailsView1$ctl01c");\r
-                       fr.Controls.Add ("DetailsView1$ctl02c");\r
 \r
-                       fr.Controls ["__EVENTTARGET"].Value = "DetailsView1$ctl03c";\r
-                       fr.Controls ["__EVENTARGUMENT"].Value = "";\r
-                       fr.Controls ["DetailsView1$ctl01c"].Value = "1";\r
-                       fr.Controls ["DetailsView1$ctl02c"].Value = "2";\r
-#endif\r
                        t.Request = fr;\r
                        t.Run ();\r
 \r
index 3c8da652417161fc268498d8d9c558a8c427f5ab..224726fc3cd4ed5545f98932c365e01612a64a3b 100644 (file)
@@ -1,3 +1,8 @@
+2007-08-06 Igor Zelmanovich <igorz@mainsoft.com>
+
+       * ControlTest.cs:
+       Added new tests.
+
 2007-06-15  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * LosFormatterTest.cs: Added tests for LosFormatter.
index 4cc4ade0121c5474098fd3f261f47677d58e93ad..4604e4bfdc8309d11bd074c9dd836813e9fcd2e6 100644 (file)
@@ -71,7 +71,16 @@ namespace MonoTests.System.Web.UI
                        Control nc = new MyNC ();
                        Assert.IsNull (nc.UniqueID, "nulltest");
                }
-
+               
+               [Test]
+               public void UniqueID1_1 () {
+                       // Standalone NC
+                       Control nc = new MyNC ();
+                       Page p = new Page ();
+                       p.Controls.Add (nc);
+                       Assert.IsNotNull (nc.UniqueID, "notnull");
+               }
+               
                [Test]
                public void UniqueID2 ()
                {
@@ -83,6 +92,18 @@ namespace MonoTests.System.Web.UI
                        Assert.IsTrue (nc.UniqueID.IndexOfAny (new char[] { ':', '$' }) == -1, "separator");
                }
 
+               [Test]
+               public void UniqueID2_1 () {
+                       // NC in NC
+                       Control nc = new MyNC ();
+                       Control nc2 = new MyNC ();
+                       nc2.Controls.Add (nc);
+                       Page p = new Page ();
+                       p.Controls.Add (nc2);
+                       Assert.IsNotNull (nc.UniqueID, "notnull");
+                       Assert.IsTrue (nc.UniqueID.IndexOfAny (new char [] { ':', '$' }) != -1, "separator");
+               }
+
                [Test]
                public void UniqueID3 ()
                {
@@ -121,6 +142,56 @@ namespace MonoTests.System.Web.UI
                        Assert.IsTrue (-1 != control.UniqueID.IndexOfAny (new char[] { ':', '$' }), "separator");
                }
 
+               [Test]
+               public void UniqueID6 () {
+                       // NC in NC
+                       Control nc = new MyNC ();
+                       Page p = new Page ();
+                       p.Controls.Add (nc);
+                       Assert.IsNotNull (nc.UniqueID, "notnull");
+
+                       Control c1 = new Control ();
+                       Control c2 = new Control ();
+                       nc.Controls.Add (c1);
+                       nc.Controls.Add (c2);
+                       string uid1_1 = c1.UniqueID;
+                       string uid2_1 = c2.UniqueID;
+
+                       nc.Controls.Clear ();
+
+                       Assert.IsNull (c1.UniqueID);
+                       Assert.IsNull (c2.UniqueID);
+
+                       // ad in another order
+                       nc.Controls.Add (c2);
+                       nc.Controls.Add (c1);
+                       string uid1_2 = c1.UniqueID;
+                       string uid2_2 = c2.UniqueID;
+
+                       Assert.IsFalse (uid1_1 == uid1_2);
+                       Assert.IsFalse (uid2_1 == uid2_2);
+                       Assert.AreEqual (uid1_1, uid2_2);
+                       Assert.AreEqual (uid2_1, uid1_2);
+
+                       nc.Controls.Remove (c1);
+                       nc.Controls.Add (c1);
+                       string uid1_3 = c1.UniqueID;
+                       Assert.IsFalse (uid1_3 == uid1_2, "id was not reset");
+
+#if NET_2_0
+                       EnsureIDControl c3 = new EnsureIDControl ();
+                       nc.Controls.Add (c3);
+                       string uid3_1 = c3.UniqueID;
+                       c3.DoEnsureID ();
+                       Assert.IsNotNull (c3.ID);
+                       nc.Controls.Remove (c3);
+                       nc.Controls.Add (c3);
+                       string uid3_2 = c3.UniqueID;
+                       Assert.IsNull (c3.ID);
+                       Assert.IsFalse (uid3_1 == uid3_2, "id was not reset");
+#endif
+               }
+
                [Test]
                public void ClientID () 
                {
@@ -1065,6 +1136,12 @@ namespace MonoTests.System.Web.UI
        public class Customadapter : ControlAdapter
        {
        }
+
+       class EnsureIDControl : Control {
+               public void DoEnsureID () {
+                       EnsureID ();
+               }
+       }
 #endif
 
        public class ChildControlsCreatedControl : Control