title: C# adding controls in site master wont reference in asp:loginView
body: <p>I have a site master that I'm adding a few controls too one being a label that updates programmatically. I'm not sure why in the second example I cant reference the object, if maybe my understanding of how the scope works in the site master is wrong. Any assistance would be greatly appreciated!</p>
  
  <p>This "ClubName" label works as intended</p>
  
  <pre><code> &lt;div class="main"&gt;
       &lt;asp:Label ID="ClubName" runat="server"&gt;&lt;/asp:Label&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Although this one doesnt (Object reference not set to an instance of an object)</p>
  
  <pre><code>&lt;asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false"&gt;
                  &lt;AnonymousTemplate&gt;
                      [ &lt;a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server"&gt;Log In&lt;/a&gt; ]
                  &lt;/AnonymousTemplate&gt;
                  &lt;LoggedInTemplate&gt;
                      Welcome &lt;span class="bold"&gt;&lt;asp:LoginName ID="HeadLoginName" runat="server" /&gt;&lt;/span&gt;!
                      [ &lt;asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/&gt; ]
                      &lt;asp:Label ID="ClubName" runat="server" Text="Label"&gt;&lt;/asp:Label&gt;
                  &lt;/LoggedInTemplate&gt;
   &lt;/asp:LoginView&gt;
  </code></pre>
  
  <p>My code behind code is simply</p>
  
  <pre><code>public partial class SiteMaster : System.Web.UI.MasterPage
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          NameClub.Text = "hello";
      }
  </code></pre>
  
  <p>and the exception error:</p>
  
  <pre><code> Object reference not set to an instance of an object.
   Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  
   Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
  </code></pre>