- Got a
Site.Master(Masterpage) - Got
Default.aspx(Page) - And in the
Default.aspx, there is a UserControlLoginUserControl.ascxplaced
Now my problem:
In the LoginUserControl I check if Login is right.
If yes, then I set the Property IsLoggedIn on the Default.aspx to true:
//Inside LoginUserControl.ascx
if (/*Login is Ok*/)
{
((Default)Page).IsLoggedIn = true;
}
So, now I need this Information in my Masterpage Site.Master
I must know if User is logged in or not.. I do this:
//Inside Site.Master
protected void Page_Load(object sender, EventArgs e)
{
if (((Default)Page).IsLoggedIn)
{
//Do Something
}
}
But its ALWAYS false! Why? I thought I set the IsLoggedIn = true ?! Why is it then false? Is it a Lifecycle problem and what I must do, that it works 🙁
You should add the property IsLogged on to the viewstate of the page.
Or if the property is used over multiple pages you should add it to the Session (replace ViewState with Session)