title: Access control in masterpage from shared function of same masterpage
body: <p>I'm calling a shared function of a masterpage from a content page. In that shared function I want to access a control in the masterpage, but I don't know how.</p>
  
  <p><strong>main.master</strong></p>
  
  <pre><code>&lt;asp:Literal ID="ltCurrency" runat="server" /&gt;
  </code></pre>
  
  <p><strong>main.master.vb</strong></p>
  
  <pre><code>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 &lt;&gt; "" 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
  </code></pre>
  
  <p>'I also tried instantiating a new class of the current masterpage:
  Ctype(main,Masterpage).CurrencyText</p>
  
  <pre><code>End Function
  
  
  End Class
  </code></pre>
  
  <p>From page1.aspx I call:</p>
  
  <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      main.DoSomething()
  End Sub
  </code></pre>
  
  <p>What else can I do?</p>