Solved

How to make a panel invisible

Posted on 2010-11-08
7
471 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
Technology Partners: 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!

 

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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