Solved

How to make a panel invisible

Posted on 2010-11-08
7
474 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 75

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 75

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

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

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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