Solved

How to make a panel invisible

Posted on 2010-11-08
7
469 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 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RLDC Reporting in Visual studio 11 29
Finding the IIS version 5 21
How to Generate a Method from a keyboard shortcut in Visual Studio? 2 19
Input parameteres to DragOver 2 19
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

840 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