Link to home
Start Free TrialLog in
Avatar of tantormedia
tantormediaFlag for United States of America

asked on

How to make a panel invisible

Dear experts,

I have a Panel in my Master page:
                                                                                    <asp:Panel ID="pnlSettings"  runat="server" >
                                                                                        [<asp:LinkButton ID="btnSettings"  runat="server" Text="Settings" OnClick="btnSettings_Click" />]
                                                                                    </asp:Panel>

I want it to be invisible for certain users. I tried it in my Page's Page_Init():
if(some conditions)
{
                    Panel pnlSettings = ((TPSMasterPage)Master).GetControl((TPSMasterPage)Master, "pnlSettings") as Panel;
                    if (pnlSettings != null)
                    {
                        pnlSettings.Visible = false;
                    }
}
This code is executed, but the Panel is still visible.
I tried to move it to Master page's Page_Load(), with the same result. What am I doing wrong?
Thanks.
Avatar of kaufmed
kaufmed
Flag of United States of America image

You could create a public property on your master page which exposes the panel. Then you can interact with it directly instead of using FindControl.

As far as "Visible = false," that approach has worked form me.
// Example
//////////////////////////////////////
// On master page
//////////////////////////////////////
public Panel LogoutPanel
{
    get { return this.pnlLogout; }
}


//////////////////////////////////////
// On content page
//////////////////////////////////////
((Main)this.Master).LogoutPanel.Visible = false;

Open in new window

Avatar of tantormedia

ASKER

Thank you for your response.

Would my code work for you? Do you have any idea why it doesn't work for me?
>>  I tried to move it to Master page's Page_Load()

Have you tried the content page's Page_Load() ?
Yes, I tried it now, with no success.
ASKER CERTIFIED SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No, doesn't help :(
Figured it out. The problem was that I had two panels with the same id. Sorry for the confusion.