Example #1
0
        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);
        }
Example #2
0
        public static T FindControl <T>(Control seed, string id, bool traverse, Control branch) where T : Control
        {
            Control control = ControlUtils.FindControl(seed, id, traverse, branch);

            if (control != null && !ReflectionUtils.IsTypeOf((object)control, 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}.", (object)id, (object)typeof(T).ToString(), (object)control.GetType().ToString()));
            }
            return(control as T);
        }
Example #3
0
        private static Control FindControl(
            Control seed,
            string id,
            bool traverse,
            Control branch)
        {
            if (seed == null || string.IsNullOrEmpty(id))
            {
                return((Control)null);
            }
            Control control1 = (Control)null;

            try
            {
                control1 = seed.FindControl(id);
                if (control1 != null)
                {
                    return(control1);
                }
            }
            catch (HttpException ex)
            {
            }
            Control branch1 = seed is INamingContainer ? seed : seed.NamingContainer;
            string  str     = branch != null ? branch.ID ?? "" : "";

            foreach (Control control2 in branch1.Controls)
            {
                if (!str.Equals(control2.ID) && ControlUtils.HasControls(control2))
                {
                    control1 = ControlUtils.FindChildControl(control2, id);
                }
                if (control1 != null)
                {
                    break;
                }
            }
            if (traverse && control1 == null)
            {
                control1 = ControlUtils.FindControl(branch1.NamingContainer, id, traverse, branch1);
            }
            return(control1);
        }
Example #4
0
 public static T FindControl <T>(Control seed) where T : Control
 {
     return(ControlUtils.FindControl(seed, typeof(T)) as T);
 }
Example #5
0
 public static T FindControl <T>(Control seed, string id, bool traverse) where T : Control
 {
     return(ControlUtils.FindControl <T>(seed, id, traverse, (Control)null));
 }
Example #6
0
 public static Control FindControl(Control seed, string id, bool traverse)
 {
     return(ControlUtils.FindControl(seed, id, traverse, (Control)null));
 }
Example #7
0
 public static Control FindControl(Control seed, string id)
 {
     return(ControlUtils.FindControl(seed, id, true, (Control)null));
 }
Example #8
0
 public static Control FindControl(Control seed, Type type)
 {
     return(ControlUtils.FindControl(seed, type, false));
 }
Example #9
0
 public static T FindControl <T>(Control seed, bool shallow) where T : Control
 {
     return(ControlUtils.FindControl(seed, typeof(T), shallow) as T);
 }
Example #10
0
 public static T FindControl <T>(Control seed, string id) where T : Control
 {
     return(ControlUtils.FindControl <T>(seed, id, true, null));
 }