How to get panels from a child page in ASP.NET

1

I'm trying to grab the panels from a child page in ASP.NET, but when I use page.Controls, it only retrieves the elements from the master page.

I've tried using this, Page.Page, but always the same result, the elements of the master page and not the page in question. See the algorithm I used

public static void mostrarPanels(List<String> panels, Page page)
{
    ControlCollection controls = page.Controls;
    foreach(Control control in controls)
    {
        ControlCollection controls2 = control.Controls;
        if (control.GetType() == typeof(Panel)) {
            control.Visible = false;
            for (int i = 0; i < panels.Count; i++)
            {
                if (control.ID == panels[i])
                    control.Visible = true;
            }
        }
    }
}

Am I doing something wrong?

    
asked by anonymous 20.11.2017 / 12:16

1 answer

1
public static void mostrarPanels(List<String> panels)
{
   NomeClassControls page = (NomeClassControls)Page;
   ControlCollection controls = page.Controls;
   foreach(Control control in controls)
   {
     ControlCollection controls2 = control.Controls;
     if (control.GetType() == typeof(Panel)) {
         control.Visible = false;
        for (int i = 0; i < panels.Count; i++)
        {
            if (control.ID == panels[i])
                control.Visible = true;
        }
     }
   }
}

Try this maybe right.

    
29.11.2017 / 13:04