I have an index page as a content page and at the top of it i have a content place holder like this.
<asp:Content ID="Content3" ContentPlaceHolderID="logProcessHolder" runat="server">
<p class="header-link"><a href="LoginFormContainer.aspx">login</a> or <a href="RegisterFormContainer.aspx">create an account</a></p>
</asp:Content>
I want to change its content when users login. After login i want to put user name instead of these links. I have my login method already, just want to know how can i make this without using an another content page ? or is it a logical solution for me ? Should i use an another content page as a home page ?
I would wrap your options in asp:Panel
s or use the LoginView
control as epaezr has done
<asp:Content ID="Content3" ContentPlaceHolderID="logProcessHolder" runat="server">
<asp:Panel ID="pnlAnonymous" runat="server">
<p class="header-link"><a href="LoginFormContainer.aspx">login</a> or <a href="RegisterFormContainer.aspx">create an account</a></p>
</asp:Panel>
<asp:Panel ID="pnlVerified" runat="server">
<asp:Literal ID="litUserName" runat="server" />
</asp:Panel>
</asp:Content>
Then in your code behind
protected void Page_Load(object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
pnlAnonymous.Visible = false;
pnlVerified.Visible = true;
litUserName.Text = Context.User.Identity.Name;
}
else
{
pnlAnonymous.Visible = true;
pnlVerified.Visible = false;
}
}
You don't have to use panels. You could also HTML elements and access them in the code-behind by giving them an ID and a runat="server"
attribute. E.g: <p ID="loginLinks" runat="server" class="header-link">...etc...</p>
where you could change the visibility with loginLinks.Visible