1. The FindControl method is used to find the range of the Child Control of the given Control.
Copy codeThe Code is as follows:
<Form id = "form1" runat = "server">
<Asp: Label ID = "Label1" runat = "server" Text = "Label"> </asp: Label>
<Asp: Panel ID = "Panel1" runat = "server">
<Asp: TextBox ID = "TextBox1" runat = "server"> </asp: TextBox>
<Asp: Button ID = "Button1" runat = "server" Text = "Button"/>
</Asp: Panel>
</Form>
As shown in the above Code, Panel1.FindControl ("Button1") is used in the background to search for it. The smaller range can improve efficiency. In fact, TextBox1.FindControl ("Button1") can also be found. As mentioned earlier, the FindControl method is to find the corresponding Control in the name container where the Control is located based on the ID. When TextBox1.FindControl ("Button1") is executed, ASP. NET first obtains TextBox1.NamingContainer, whose value is the page itself (the last generated xxxx_aspx class instance), and then recursively searches for the control of the corresponding ID, so Button1 can be found in the same way.
Similarly, if TextBox1.FindControl ("Label1") is used, Label1 can also be found.
2. I don't understand why the controls in the GridView cannot be found in this. FindControl method.
In fact, it is easy to understand that the FindControl method is only searched under the naming container, and will not be searched in other naming containers, while the naming container (NamingContainer) is not just the page itself, it also includes GridViewRow, DataListItem, RepeaterItem, UserControl, MasterPage, and many other controls that inherit the INamingContainer interface, one of their notable features is that the UniqueID and ClientID of its child controls are generally different from the ID (except the top-level page object ).
3. The FindControl operation efficiency is poor.
ASP. NET runtime analysis of aspx, ascx, master and other file label structure, generate a Dom-like control tree, the query efficiency of the tree is generally relatively high, especially when the problem scale is not large. In general, the number of controls on the actual page cannot be tens of thousands, and the search cannot go beyond the named container. These factors limit the size of the problem. Therefore, FindControl is not efficient.