Reputation: 932
public partial class Page1 :System.Web.UI.Page
{
public static LGDP.LDGPSession var1 = null;
private void Login(this, EventArgs e)
{
var1 = new LGDPSession(this, data, data);
}
public bool IsLoggedIn()
{
bool login = false;
if (var1 != null)
{
login = true;
}
return var1;
}
}
How do I access the Page1 static var1 or function IsLoggedIn() from Page2.apsx ?
public partial class Page2 :System.Web.UI.Page
{
Page1.(nothing shows up here)
}
ANSWER ----- created separate class and accessed public var in pageload / postback
private static bool _login = false;
public static void SetLoggedIn(object lgdps)
{
if (lgdps == null)
{
_login = false;
}
if (lgdps != null)
{
_login = true;
}
}
public static bool IsLogin
{
get { return _login; }
}
Upvotes: 1
Views: 1201
Reputation: 4817
It's better to create a base class with your functions in it:
public class BasePage : Page
{
public bool IsLoggedIn()
{
bool login = false;
if (var1 != null)
{
login = true;
}
}
}
And then you can access IsLoggedIn
from you pages when you inherit from BasePage
public partial class Page1 : BasePage
{
}
public partial class Page2 : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
if(IsLoggedIn())
{
}
}
}
Upvotes: 0
Reputation: 700800
Your function IsLoggedIn
in Page1
doesn't compile. It has to return something:
public bool IsLoggedIn()
{
bool login = false;
if (var1 != null)
{
login = true;
}
return login;
}
Or simply:
public bool IsLoggedIn()
{
return var1 != null;
}
Once the page compiles, its members should show up in the intellisense.
Upvotes: 3