由于其保护级别,面板无法访问

编程入门 行业动态 更新时间:2024-10-27 03:26:43
本文介绍了由于其保护级别,面板无法访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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">

我使用以下代码在second.aspx.cs上访问它 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 the first 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.

更多推荐

由于其保护级别,面板无法访问

本文发布于:2023-11-26 19:56:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634971.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:于其   面板   无法访问   级别

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!