Bladeren bron

2005-03-09 Gonzalo Paniagua Javier <[email protected]>

	* Control.cs: in FindControl, throw if there's more than one control
	with the same ID. Fixes bug #73479.


svn path=/trunk/mcs/; revision=41622
Gonzalo Paniagua Javier 21 jaren geleden
bovenliggende
commit
39eb2bb963
2 gewijzigde bestanden met toevoegingen van 35 en 17 verwijderingen
  1. 5 0
      mcs/class/System.Web/System.Web.UI/ChangeLog
  2. 30 17
      mcs/class/System.Web/System.Web.UI/Control.cs

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

@@ -1,3 +1,8 @@
+2005-03-09 Gonzalo Paniagua Javier <[email protected]>
+
+	* Control.cs: in FindControl, throw if there's more than one control
+	with the same ID. Fixes bug #73479.
+
 2005-03-04  Lluis Sanchez Gual <[email protected]>
 
 	* Page.cs: Load control state before loading view state, and the

+ 30 - 17
mcs/class/System.Web/System.Web.UI/Control.cs

@@ -510,26 +510,39 @@ namespace System.Web.UI
                 {
 			return FindControl (id, 0);
                 }
-
-		Control LookForControlByName (string id)
-		{
+
+		Control LookForControlByName (string id)
+		{
 			if (!HasControls ())
 				return null;
-
+
+			Control result = null;
 			foreach (Control c in Controls) {
-				if (String.Compare (id, c._userId, true) == 0)
-					return c;
-
-				if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ()) {
-					Control child = c.LookForControlByName (id);
-					if (child != null)
-						return child;
-				}
-			}
-
-			return null;
-		}
-		
+				if (String.Compare (id, c._userId, true) == 0) {
+					if (result != null && result != c) {
+						Console.WriteLine (c.GetHashCode ());
+						Console.WriteLine (result.GetHashCode ());
+						throw new HttpException ("1 Found more than one control with ID '" + id + "'");
+					}
+
+					result = c;
+					continue;
+				}
+
+				if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ()) {
+					Control child = c.LookForControlByName (id);
+					if (child != null) {
+						if (result != null && result != child)
+							throw new HttpException ("2 Found more than one control with ID '" + id + "'");
+
+						result = child;
+					}
+				}
+			}
+
+			return result;
+		}
+
                 protected virtual Control FindControl (string id, int pathOffset)
                 {
 			EnsureChildControls ();