ASP.NET Interview Questions

Write a C# code to get list of parent ASP.NET controls from Child ASP.NET controls

C# code to get list of parent ASP.NET controls from Child ASP.NET controls

private ArrayList WalkthroughContainers(Control ctl)
    {
        ArrayList retContainers = new ArrayList();
        Control parent = ctl.NamingContainer;
        if (parent != null)
        {
            ArrayList sublist = WalkContainers(parent);
            for (int j = 0; j < sublist.Count; j++) retContainers.Add(sublist[j]);
        }
        retContainers.Add(ctl.GetType().Name);
        return retContainers;
    }

Leave a Reply