不是ASP.masterpage_master的成员

时间:2014-06-19 22:35:47

标签: .net vb.net visual-studio-2012

我创建了自己的MasterPage,名为MyMasterPage.master。

<%@ Master Language="VB" Inherits="AMasterPage" CodeBehind="MyMasterPage.master.vb" AutoEventWireup="true" %>

在MyMasterPage.master.vb背后的代码中,我添加了与MasterPage.master文件中的Inherits相匹配的代码

Partial Class AMasterPage
Inherits System.Web.UI.MasterPage

我也在我的代码隐藏中设置了一个公共属性

Public Property MyProperty() As String
    Get
        If String.IsNullOrEmpty(_myProperty) Then
            _myProperty = "a property"
        End If
        Return _myProperty 
    End Get
    Set(ByVal value As String)
        _myProperty = value
    End Set
End Property

当我尝试从我的MyMasterPage.master文件中访问属性后面的代码时,就像这样

<%=Me.MyProperty%>

我收到错误&#39; MyProperty&#39;不是ASP.masterpage_master的成员

1 个答案:

答案 0 :(得分:0)

我不确定这是否是一个好答案。可能真糟糕:

对于VB.net:

将会话作为mySession = master.GetType()。GetMethod(“ getMySession”)。Invoke(master,obj)

尽管如此,您可能希望将我的GetMethod与GetProperty交换: https://docs.microsoft.com/en-us/dotnet/api/system.type.getproperty?view=netframework-4.8#System_Type_GetProperty_System_String_System_Type_ 当您尝试获取财产时

相关问题