自定义控件文件:
TabControl.cs 
TabPage.csDiscuz NT上有 代震军blog里有  http://www.cnblogs.com/daizhj/archive/2007/08/22/864281.html 调用:    <cc1:TabControl ID="TabControl1" runat="server">
    <cc1:TabPage ID="tabPage1"  Caption="缩略图"  >
           <asp:DataList ID="DataList1" runat="server" >
            </asp:DataList>
    </cc1:TabPage>
    <cc1:TabPage ID="tabPage2"  Caption="列表" Visible="false">
            ......
    </cc1:TabPage>
    </cc1:TabControl>Page.FindControl("DataList1")时找到不到DataList控件.

解决方案 »

  1.   

    这点有注意因除了FindControl()  Master().FindControl() 我还专写了一个遍历的.
      

  2.   


    DataList1在Tabpage里面,你试试:
    TabPage  tp=Page.FindControl("tabPage1") as TabPage;
    if(tp!=null)
    {
      DataList dl= tp.Controls[DataList1] as DataList1;
    }或者直接用
    DataList1,不是Findcontrol
      

  3.   


    tp.Controls[DataList1] as DataList; 这个也试了不行.我写了一个遍历的,发现放在TabPage里的控件遍里不到.    void IterateThroughChildren(Control parent)
        {
            foreach (Control c in parent.Controls)
            {
                lblControlList.Text += "<li>" + c.ID + "</li>";
                if (c.Controls.Count > 0)       // 判断该控件是否有下属控件。
                {
                    lblControlList.Text += "<ul>";
                    IterateThroughChildren(c);    //递归,访问该控件的下属控件集。
                    lblControlList.Text += "</ul>";
                }
            }
        }