public static Control FindChildControl(Control seed, string typeFullName, bool shallow) { if (seed == null || string.IsNullOrEmpty(typeFullName)) { return(null); } Control found = null; foreach (Control control in seed.Controls) { if (ReflectionUtils.IsTypeOf(control, typeFullName, shallow)) { found = control; } else if (ControlUtils.HasControls(control)) { found = ControlUtils.FindChildControl(control, typeFullName, shallow); } if (found != null) { break; } } return(found); }
private static Control FindControl(Control seed, string id, bool traverse, Control branch) { if (seed == null || string.IsNullOrEmpty(id)) { return(null); } Control found = null; try { found = seed.FindControl(id); if (found != null) { return(found); } } catch (HttpException) { /// TODO: Notes regarding the FindControl Method. // We need to call the native .FindControl because .EnsureChildControls() // can only be called internally by a Control. // If protected .FindControl finds the control, we just return the found control. // There is a bug in Visual Studio Design-Mode which causes protected/native // .FindControl to think it's found two controls with the same ID, although only // one exists. The conflict appears to be coming from a cached version of the assembly. // Might be related to the following Microsoft KB834608 article, see // http://support.microsoft.com/default.aspx/kb/834608 // start checking .ID property } Control root = (seed is INamingContainer) ? seed : seed.NamingContainer; string exclude = (branch != null) ? branch.ID ?? "" : ""; foreach (Control control in root.Controls) { if (!exclude.Equals(control.ID) && ControlUtils.HasControls(control)) { found = ControlUtils.FindChildControl(control, id); } if (found != null) { break; } } if (traverse && found == null) { found = ControlUtils.FindControl(root.NamingContainer, id, traverse, root); } return(found); }
public static T FindChildControl <T>(Control seed, string id) where T : Control { Control c = ControlUtils.FindChildControl(seed, id); if (c != null && !ReflectionUtils.IsTypeOf(c, typeof(T))) { throw new InvalidCastException(string.Format("The Control ID ('{0}') was found, but it was not a type of {1}. The found Control was a type of {2}.", id, typeof(T).ToString(), c.GetType().ToString())); } return(c as T); }
private static Control FindControlByTypeName(Control seed, string typeFullName, bool shallow, bool traverse, Control branch) { if (seed == null || string.IsNullOrEmpty(typeFullName)) { return(null); } Control root = (seed is INamingContainer) ? seed : seed.NamingContainer; if (ReflectionUtils.IsTypeOf(root, typeFullName, shallow)) { return(root); } Control found = null; string exclude = (branch != null) ? branch.ID ?? "" : ""; foreach (Control control in root.Controls) { if (!exclude.Equals(control.ID)) { if (ReflectionUtils.IsTypeOf(control, typeFullName, shallow)) { found = control; } else if (ControlUtils.HasControls(control)) { found = ControlUtils.FindChildControl(control, typeFullName, shallow); } if (found != null) { break; } } } if (traverse && found == null) { found = ControlUtils.FindControlByTypeName(root.NamingContainer, typeFullName, shallow, traverse, root); } return(found); }
/* FindChildControl * -----------------------------------------------------------------------------------------------*/ /// <summary> /// /// </summary> /// <param name="seed"></param> /// <param name="id"></param> /// <returns></returns> public static Control FindChildControl(Control seed, string id) { if (seed == null || string.IsNullOrEmpty(id)) { return(null); } Control found = null; try { found = seed.FindControl(id); if (found != null) { return(found); } } catch (HttpException) { } //Control root = (seed is INamingContainer) ? seed : seed.NamingContainer; foreach (Control control in seed.Controls) { if (ControlUtils.HasControls(control)) { found = ControlUtils.FindChildControl(control, id); } if (found != null) { break; } } return(found); }
public static T FindChildControl <T>(Control seed, bool shallow) where T : Control { return(ControlUtils.FindChildControl(seed, typeof(T), shallow) as T); }
public static T FindChildControl <T>(Control seed) where T : Control { return(ControlUtils.FindChildControl(seed, typeof(T), false) as T); }