I am using asp.net LoginView to show different data to authenticated and anonymous users.
<asp:LoginView ID="LoginView1" Runat="server">
<LoggedInTemplate>
<asp:Label ID="Foo" runat="server" />
</LoggedInTemplate>
<AnonymousTemplate>
<asp:Label ID="Bar" runat="server" />
</AnonymousTemplate>
</asp:LoginView>
I then access these labels in my c# file like this:
Label Foo = (Label)LoginView1.FindControl("Foo");
Foo.Text = "whatever";
The error I am getting reads:
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.