Simple ASP.NET problem

Izi

Izi

Soldato
Joined
9 Dec 2007
Posts
2,718
PHP:
public void ShowBlackBarButtonsPanel(string panelName)
    {
        Control pnl = this.FindControl(panelName);
        pnl.Visible = true;
    }

The above snippet is my Master Page.

From my page I set

Master.ShowBlackBarButtonsPanel("A Panel Name");

However, I get a "Object reference not set to an instance of an object." error as its not finding the control in my master page.

The panel name defo exists, what am i doing wrong?
 
I think the panel name will be different from the perspective of the master page.

In each content section the control ids are all changed so that they are unique.
 
PHP:
public 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;
    }

Ok, so I managed to fix this using the above static method:

PHP:
Panel pnl = FindControlRecursive(this, panelName) as Panel;
        pnl.Visible = true;

But i still dont understand why...
 
I think the panel name will be different from the perspective of the master page.

In each content section the control ids are all changed so that they are unique.

if in the masterpage i start writing [panelname][dot] i get all options for the panel name in intellisence.

Thats why with 'this'[dot] should find the control. 'this' refers to the current object which is the master page.

confused.

EDIT: i see what you mean, how do you get around this?
 
Last edited:
Back
Top Bottom