Reputation: 131
I am using a label to tell a user if he's logged in to a website or isn't. So what I have done is a added a label and used a if/else statement. But the thing is. I want 1 link label to have two text values
"logged in" && "Logged out."
So here's the problem. I have the code but I have to click the label before it update the label value:
private void label1_Click(object sender, EventArgs e)
{
if (1 == 2)
{
label1.Text = "Logged out";
}
else
{
label1.Text = "Logged in";
}
}
I can't find another one where I could put the code so I don't have to click it. Also, ignore the if(1==2) I have just done that for debugging.
Thank you.
Upvotes: 0
Views: 203
Reputation: 698
Are you creating your site using Visual Studio + ASP.
<asp:LoginStatus ID="LoginStatus1" runat="server" />
Then there is a tool in the toolbox for this.
Or you can add this to page load.
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Code
}
}
Upvotes: 0