How to get panels from a daughter page on Asp.net

Asked

Viewed 72 times

1

I’m trying to get the panels from a daughter page on Asp.net, but when I use the page. Controls, it only retrieves the elements from the master page.

I have tried 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;
            }
        }
    }
}

I’ll be doing something wrong?

  • Hello! See if this answer helps: https://stackoverflow.com/a/277654/1377664

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 for real.

  • Thanks, but I got it sorted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.