Better way to find control in ASP.NET

后端 未结 9 1418
太阳男子
太阳男子 2020-11-22 03:17

I have a complex asp.net form,having even 50 to 60 fields in one form like there is Multiview, inside MultiView I have a GridView, and inside GridV

9条回答
  •  野的像风
    2020-11-22 03:57

    https://blog.codinghorror.com/recursive-pagefindcontrol/

    Page.FindControl("DataList1:_ctl0:TextBox3");
    

    OR

    private Control FindControlRecursive(Control root, string id)
    {
        if (root.ID == id)
        {
            return root;
        }
        foreach (Control c in root.Controls)
        {
            Control t = FindControlRecursive(c, id);
            if (t != null)
            {
                return t;
            }
        }
        return null;
    }
    

提交回复
热议问题