Solved

How to make a panel invisible

Posted on 2010-11-08
7
458 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:tantormedia
  • 4
  • 2
7 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 34087371
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

0
 

Author Comment

by:tantormedia
ID: 34087392
Thank you for your response.

Would my code work for you? Do you have any idea why it doesn't work for me?
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 34087404
>>  I tried to move it to Master page's Page_Load()

Have you tried the content page's Page_Load() ?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:tantormedia
ID: 34087922
Yes, I tried it now, with no success.
0
 
LVL 19

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 34087950
Here is how you do this:

1.  In your Mastter Page ASPX:
   In the <form> tag:
       <asp:Panel ID="_prvPanelTest" runat="server">
       <asp:LinkButton ID="_prvLinkButtonTest" runat="server" Text="My Test LinkButton">
       </asp:LinkButton>
    </asp:Panel>  

2.  In the MasterPage code-behind (cs file):

        private bool _prvShowLinkButton = false;
        public bool _pubShowLinkButton
        {
            get
            {
                return _prvShowLinkButton;
            }
            set
            {
                _prvShowLinkButton = value;
                _prvPanelTest.Visible = value;
            }
        }

and:
        protected void Page_Load( object sender, EventArgs e )
        {
            _prvPanelTest.Visible = _pubShowLinkButton;
        }

3.  Then, in the ASPX file that uses the Master Page:
     Add this right under the @Page directive.
<%@ MasterType VirtualPath="~/AycoDocuments.Master" %>

4.  Then, in the code-behind for this ASPX page:

        protected void Page_Load( object sender, EventArgs e )
        {
            Master._pubShowLinkButton = false;
        }

and it will not show up on the ASPX page.
0
 

Author Comment

by:tantormedia
ID: 34093093
No, doesn't help :(
0
 

Author Comment

by:tantormedia
ID: 34093538
Figured it out. The problem was that I had two panels with the same id. Sorry for the confusion.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now