Reputation: 517
Hi all and thanks in advance.
I have created a base page that defines two classes, one that manages variables for the pages themselves and one that manages the output of the Master pages:
public class MyBasePage : BasePage
{
public bool IsEmployee;
protected new void Page_Init(object sender, EventArgs e)
{
base.Page_Init(sender,e);
IsEmployee = GetEmployee();
}
}
public class MyMasterBasePage : BaseMasterPage
{
public new void Page_Init(Object sender, EventArgs e)
{
base.Page_Init(sender,e);
session = GetSession();
}
}
I need to access the IsEmployee from the master page. I tried actually calling an instance of the base page on the master page and then trying to invoke it but the bool comes back false and I tried to do the same directly from the class with the same results. I could put the values into session but I really don't want to do that. Is there another way to access the variable?
Upvotes: 0
Views: 389
Reputation: 15893
public class MyMasterBasePage : BaseMasterPage
{
...
private bool IsEmployee
{
get
{
if (Page is MyBasePage)
return ((MyBasePage)Page).IsEmployee;
else
return false;
}
}
}
Update:
public class MyBasePage : BasePage
{
public bool? isEmployee;
public bool IsEmployee
{
get
{
if (!isEmployee.HasValue)
{
isEmployee.Value = GetEmployee();
}
return isEmployee.Value;
}
}
}
And remove line
IsEmployee = GetEmployee();
from MyBasePage.Page_Init
.
Upvotes: 1