VB.net(VS 2005)用户类访问maindisplay.master.VB的公共变量
我试图从用户类访问母版页类的公共成员 在我的母版页中,我有:VB.net(VS 2005)用户类访问maindisplay.master.VB的公共变量,vb.net,master,Vb.net,Master,我试图从用户类访问母版页类的公共成员 在我的母版页中,我有: Partial Class MainDisplay Inherits System.Web.UI.MasterPage Public Shared m_test As Integer ... 在我的用户类中,我有: Imports Microsoft.VisualBasic Imports System.Web.UI.MasterPage Public Class mytest Public Function get
Partial Class MainDisplay
Inherits System.Web.UI.MasterPage
Public Shared m_test As Integer
...
在我的用户类中,我有:
Imports Microsoft.VisualBasic
Imports System.Web.UI.MasterPage
Public Class mytest
Public Function getValue() As Integer
Dim iRet As Integer = 0
iRet = Master.m_test ' how do i get access to the public member**
End Function
End Class
如何从用户类访问m_测试
谢谢我的VB有点生疏,但我注意到的第一件事是,带有共享成员的类被称为
main display
,但当您尝试访问共享成员时,您将其引用为Master
。如果您将其引用为main display
(请注意,您可能需要完全限定名称空间或在mytest
类文件中导入名称空间)。由于我是新手,您的粗糙度可能比我的vb好。我不确定如何引用母版页。Master或MainDisplay对我没有任何作用。@Neato:mytest的mytest
类是否与MainDisplay
类位于同一命名空间中?如果没有,则需要在包含main display
的命名空间的mytest
类文件顶部添加一行Imports
(很可能不是System.Web.UI.MasterPage
或System
下的任何内容,而是特定于项目/代码的命名空间),是否导入System.Web.UI.MasterPage
甚至编译?这是一个类,不是命名空间。mytest与MainDisplay不在同一命名空间中。MainDisplay继承自system.web.ui.masterpage。我可以确定它不在名称空间中。@Neato:它没有包装在名称空间指令中吗?它肯定在一个名称空间中,这只是一个名称空间是什么的问题。如果您使用的是Visual Studio,那么它应该能够建议正确的命名空间,作为对main display
的引用将生成的编译器错误的响应。如果MainDisplay
类文件中没有名称空间,我建议显式添加一个名称空间。喜欢显性而不是隐性。