示例#1
0
        /*  Misc
         *  -----------------------------------------------------------------------------------------------*/

        public static Control FindControlByClientID(Control seed, string clientID, bool traverse, Control branch)
        {
            if (seed == null || string.IsNullOrEmpty(clientID))
            {
                return(null);
            }

            Control parent = (seed is INamingContainer) ? seed : seed.NamingContainer;

            if (clientID.Equals(parent.ClientID ?? ""))
            {
                return(parent);
            }

            Control found        = null;
            string  exclude      = (branch != null) ? branch.ClientID ?? "" : "";
            string  tempID       = "";
            string  tempClientID = "";

            List <Control> waiting = new List <Control>();

            foreach (Control c in parent.Controls)
            {
                tempID       = c.ID ?? "";
                tempClientID = c.ClientID ?? "";

                if (clientID.Equals(tempID) || clientID.Equals(tempClientID))
                {
                    found = c;
                }
                else if (ControlUtils.HasControls(c) && (exclude.IsEmpty() || !exclude.Equals(tempClientID)))
                {
                    found = ControlUtils.FindChildControlByClientID(c, clientID);
                }

                if (found != null)
                {
                    break;
                }
            }

            if (traverse && found == null)
            {
                found = ControlUtils.FindControlByClientID(parent.NamingContainer, clientID, true, parent);
            }

            return(found);
        }
示例#2
0
        public static Control FindControlByClientID(
            Control seed,
            string clientID,
            bool traverse,
            Control branch)
        {
            if (seed == null || string.IsNullOrEmpty(clientID))
            {
                return((Control)null);
            }
            Control branch1 = seed is INamingContainer ? seed : seed.NamingContainer;

            if (clientID.Equals(branch1.ClientID ?? ""))
            {
                return(branch1);
            }
            Control        control1    = (Control)null;
            string         text        = branch != null ? branch.ClientID ?? "" : "";
            List <Control> controlList = new List <Control>();

            foreach (Control control2 in branch1.Controls)
            {
                string str1 = control2.ID ?? "";
                string str2 = control2.ClientID ?? "";
                if (clientID.Equals(str1) || clientID.Equals(str2))
                {
                    control1 = control2;
                }
                else if (ControlUtils.HasControls(control2) && (text.IsEmpty() || !text.Equals(str2)))
                {
                    control1 = ControlUtils.FindChildControlByClientID(control2, clientID);
                }
                if (control1 != null)
                {
                    break;
                }
            }
            if (traverse && control1 == null)
            {
                control1 = ControlUtils.FindControlByClientID(branch1.NamingContainer, clientID, true, branch1);
            }
            return(control1);
        }