Monday, January 2, 2017

Find Control in .NET using Control ID

Here is a snippet that I have used to find a control in ASP.NET recursively:


private static Control FindControlRecursive(Control Root, string Id)
{
            if (Root.ID == Id)
            {
                return Root;
            }
            foreach (Control Ctl in Root.Controls)
            {
                Control FoundCtl = FindControlRecursive(Ctl, Id);
                if (FoundCtl != null)
                {
                    return FoundCtl;
                }
            }
            return null;
        }

No comments:

Post a Comment