title: asp.NET: Can't access label on Master Page from Content Page
body: <p>I have an <code>asp:Label</code> control called <code>MyLabel</code> on my Master page inside an <code>asp:LoginView</code> control called <code>lvMaster</code> that I want to be able to change from the content page code behind.</p>
  
  <p>I have the following code on my Master page code-behind:</p>
  
  <pre><code>public string MyLabel
  {
      get
      {
          var lblMyLabel = (Label)lvMaster.FindControl("lblMyLabel");
          return lblMyLabel.Text;
      }
      set
      {
          var lblMyLabel = (Label)lvMaster.FindControl("lblMyLabel ");
          lblMyLabel .Text = value;
      }
  }
  </code></pre>
  
  <p>And I have this on my content page on the page load:</p>
  
  <pre><code>Master.MyLabel = "My Text";
  </code></pre>
  
  <p>This seems to work perfectly fine when I run it but when I upload it to our hosting server I get the following error:</p>
  
  <blockquote>
    <p>System.NullReferenceException: Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>How can I resolve this?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I've realized now that this problem only occurs when the user is not logged in (i.e. if the user is not an already logged in admin).  So the solution to this would be running <code>Master.MyLabel = "My Text";</code> in an <code>if(&lt;user is logged in&gt;) { }</code> block.  What should I do there?</p>