* 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
+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.
#if NET_2_0
const int ENABLE_THEMING = 1 << 16;
#endif
+ const int AUTOID_SET = 1 << 17;
/*************/
static Control () {
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 {
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;
}
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) {
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) {
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
{
}
}
+ 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 () {
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);
}
}
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 ();
}
+2007-08-06 Igor Zelmanovich <igorz@mainsoft.com>
+
+ * DataGridTest.cs:
+ * DetailsViewTest.cs:
+ fixed tests.
+
2007-07-01 Igor Zelmanovich <igorz@mainsoft.com>
* GridViewTest.cs:
#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;
#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;
#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;
#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;
#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;
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
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
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
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
+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.
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 ()
{
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 ()
{
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 ()
{
public class Customadapter : ControlAdapter
{
}
+
+ class EnsureIDControl : Control {
+ public void DoEnsureID () {
+ EnsureID ();
+ }
+ }
#endif
public class ChildControlsCreatedControl : Control