I’m using the asp.net LoginView to show different data to authenticated or 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>
When I moved Foo and Bar into LoginView1, I was unable to access them from the code behind in this fashion:
Foo.Text = "I am Foo";
Bar.Text = "I am Bar";
I was able to access them in this fashion before moving them into the LoginView. What (clean) method can I use to access these labels?
You need to use FindControl on the LoginView, and Cast appropriately as shown below: