【发布时间】:2016-04-25 17:07:42
【问题描述】:
母版页结构
TOP MASTER
PAGE MASTER "TopMaster.ErrorMsg(ErrMsg) Here throws NO error"
PAGE "TopMaster.ErrorMsg(ErrMsg) Here throws error"
我无法从基本页面访问顶级类。
顶级大师 ASPX
<asp:Literal ID="litMsg" runat="Server"/>
PAGE.VB
Partial Public Class BasePage
Inherits System.Web.UI.Page
Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
TopMaster.ErrorMsg(ErrMsg)
"Error BC30451: TopMaster is not declared it may be inaccessible due to its protection level."
End Sub
End Class
MASTER.VB
Partial Public Class PageMaster
Inherits System.Web.UI.MasterPage
End Class
TOP MASTER.VB
Partial Public Class TopMaster
Inherits System.Web.UI.MasterPage
Public Shared Sub ErrorMsg(ErrMsg As String)
Dim myPage = TryCast(HttpContext.Current.Handler, Page)
If myPage IsNot Nothing Then
Dim master = myPage.Master
Dim myMaster = TryCast(master.Master, TopMaster)
While master.Master IsNot Nothing AndAlso myMaster Is Nothing
master = master.Master
myMaster = TryCast(master, TopMaster)
End While
myMaster.litMsg.Text = ErrMsg
End If
End Sub
End Class
【问题讨论】:
-
我不明白错误“错误:未声明顶级大师”。仅当类型
TopMaster未声明或无法从您使用此类的任何位置访问时,才会发生这种情况。 -
我同意。您的代码在 Pages master 中运行良好,但现在在 master master 中找不到它。
标签: c# asp.net vb.net nested master-pages