[英]Not able to call protected method of parent page in asp.net Usercontrol
我有從基類MyBase.cs
繼承的ASP.NET頁( MyPage.aspx
)
該頁面具有1個用戶控件: ChildUser.ascx
MyBase有一種受保護的方法
protected string GetInviteeUserType(bool mustExist)
{
return "Test";
}
當UserControl嘗試像下面這樣調用此方法時
string userType = (Page is MyPage) ? ((MyPage)Page).GetInviteeUserType(): "Empty";
我收到錯誤消息說, This method is inaccessible due to protection level
。
因此,如何在用戶控件中調用此基本方法而不將其設為“ public
”。
您的Page能夠調用該方法,但是您的UserControl無法調用,因為該方法是protected
。 您可以使用internal protected
來允許您從程序集中的任何地方調用該方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.