Solved

How to make a panel invisible

Posted on 2010-11-08
7
472 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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