由于其保护级别,面板无法访问 [英] Panel is inaccessible due to its protection level
问题描述
我在frist.aspx页面上有一个面板控件,我想从frist.aspx页面访问其他second.aspx页面,如下所示:
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:Panel ID="postpanel" runat="server">
我使用以下代码在second.aspx.cs上访问它
I used following code to access it on second.aspx.cs
first d = new first();
d.postpanel.Visible = false;
但是它给出了以下错误:
first.postpanel由于其保护级别而无法访问
我尝试过:
我在frist.aspx页面上有一个面板控件,我想从frist.aspx页面访问其他second.aspx页面,如下所示:
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:Panel ID="postpanel" runat="server">
< br $>
我使用以下代码在second.aspx.cs上访问它
< br $> b $ b
I used following code to access it on second.aspx.cs
first d = new first();
d.postpanel.Visible = false;
但是它给出了以下错误:
first.postpanel由于其保护级别而无法访问
but it gives following error:
first.postpanel is inaccessible due to its protection level
推荐答案
如错误所示,
postpanel
被定义为受保护的成员。如果要在第一个
类之外访问它,可以定义公开它的公共属性(在 first.aspx.cs 中)。类似于:
As the error says,
postpanel
is defined as a protected member. If you want to access it outside of thefirst
class, you can define a public property (in first.aspx.cs) that exposes it. Something like:
public partial class first : System.Web.UI.Page
{
// ...
public Panel PostPanel
{
get { return postpanel; }
}
// ...
}
first d = new first();
d.PostPanel.Visible = false;
但是,正如KARTHIK班加罗尔写的那样,我认为没有任何理由这样做。
But, as KARTHIK Bangalore wrote, I don't see any reason of doing that.
这篇关于由于其保护级别,面板无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!