Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a panel control on frist.aspx pagewhich i want to access on other second.aspx page from frist.aspx page like following:

ASP.NET
<asp:Panel ID="postpanel" runat="server">



I used following code to access it on second.aspx.cs


C#
first d = new first();
                d.postpanel.Visible = false;


but it gives following error:
first.postpanel is inaccessible due to its protection level

What I have tried:

I have a panel control on frist.aspx pagewhich i want to access on other second.aspx page from frist.aspx page like following:

ASP.NET
<asp:Panel ID="postpanel" runat="server">



I used following code to access it on second.aspx.cs


C#
first d = new first();
                d.postpanel.Visible = false;


but it gives following error:
first.postpanel is inaccessible due to its protection level
Posted
Updated 13-Apr-16 21:59pm
Comments
Karthik_Mahalingam 14-Apr-16 4:08am    
you cannot make the panel visible/invisible by creating a new instance of the page.
its of no use;
Kishor-KW 14-Apr-16 5:04am    
but why? I want to make it invisible on one condition. what should i do?
Karthik_Mahalingam 14-Apr-16 5:09am    
You can make it visible only in its code behind file or in master page file.
if you try to make it visible in a new instance, the visible property will be in that particular instance only, not the page loaded in the browser.
Kishor-KW 14-Apr-16 5:13am    
ok thanx
Kishor-KW 14-Apr-16 5:12am    
Object reference not set to an instance of an object.

this is the error occured

1 solution

As the error says, postpanel is defined as a protected member. If you want to access it outside of the first class, you can define a public property (in first.aspx.cs) that exposes it. Something like:


C#
public partial class first : System.Web.UI.Page
{
    // ...

    public Panel PostPanel
    {
        get { return postpanel; }
    }

    // ...
}

C#
first d = new first();
d.PostPanel.Visible = false;

But, as KARTHIK Bangalore wrote, I don't see any reason of doing that.

 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900