我正在从内容页面调用母版页的共享功能。在该共享功能中,我想访问母版页中的控件,但我不知道如何。
主控
<asp:Literal ID="ltCurrency" runat="server" />
主主变种vb
Partial Public Class main
Inherits System.Web.UI.MasterPage
Public Property CurrencyText() As String
Get
Return ltCurrency.Text
End Get
Set(ByVal value As String)
If value <> "" Then
ltCurrency.Text = value
End If
End Set
End Property
Public Shared Function DoSomething() As String
ltCurrency.Text="SOME TEXT" 'throws error: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
CurrencyText="SOME TEXT" 'this property isn't found at all
'我还尝试实例化当前母版页的一个新类:Ctype(main,Masterpage).CurrencyText
End Function
End Class
从 page1.aspx 我调用:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
main.DoSomething()
End Sub
我还可以做些什么?