FindControl under MasterPage

Source: Internet
Author: User

I haven't written recursion for a long time. It's a very low-level error, T. T

The following section is taken from nobugs.

FindeControl is related to all containers (only search for the current container)
MSDN explanation:
The FindControl method can be used to access controls whose IDs are unavailable during design. This method only searches for the direct or top-level containers of a page. It does not Recursively search controls in the naming containers contained in the page. To access the controls in the subordinate named container, call the FindControl method of the container.

So what I take for granted is to find it through recursion, and then I wrote a result myself, which is the idiot error I mentioned at the beginning.

Rick Strahl has a detailed explanation, address: http://west-wind.com/WebLog/posts/5127.aspx

His code:

        public static Control FindControl(Control root, string id)        {            if (root.ID == id) return root;            foreach (Control c in root.Controls)            {                Control foundC= FindControl(c, id);                if (foundC != null)                    return foundC;            }            return null;        }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.