[asp.net] Fix for bug #649034. Control.FindControl continues to search for controls...
authorMarek Habersack <grendel@twistedcode.net>
Fri, 29 Oct 2010 12:44:56 +0000 (14:44 +0200)
committerMarek Habersack <grendel@twistedcode.net>
Fri, 29 Oct 2010 12:44:56 +0000 (14:44 +0200)
When a control is a naming container and an attempt to find a control with non-segmented id (e.g. 'myControl') is made,
the search continues to the control's naming container if pathOffset is 0, that is we're at the start of the search.

mcs/class/System.Web/System.Web.UI/Control.cs

index 74e8fe0efc9efebd5cdbf96378f38ca4b5148487..c3d27db56ec77680942ff3eb3cba7bbbdc87048a 100644 (file)
@@ -1100,8 +1100,18 @@ namespace System.Web.UI
                                return null;
                        
                        int separatorIdx = id.IndexOf (IdSeparator, pathOffset);
-                       if (separatorIdx == -1)
-                               return LookForControlByName (id.Substring (pathOffset));
+                       if (separatorIdx == -1) {
+                               if (pathOffset == 0) {
+                                       namingContainer = NamingContainer;
+                                       if (namingContainer != null) {
+                                               Control ctl = namingContainer.FindControl (id);
+                                               if (ctl != null)
+                                                       return ctl;
+                                       }
+                               }
+
+                               return LookForControlByName (pathOffset > 0 ? id.Substring (pathOffset) : id);
+                       }
 
                        string idfound = id.Substring (pathOffset, separatorIdx - pathOffset);
                        namingContainer = LookForControlByName (idfound);