I'm making a Website using Visual Studio 2015. I have 2 classes, Default:System.Web.UI.Page
and Login:System.Web.UI.Page
. Both are partial classes.
I have a function called returnUserType
from Login and I want to have it in Default so that if userType` is a certain number, the page redirects.
I tried this:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Login loginClass = new Login();
int userType = loginClass.returnUserType();
}
}
But it says Login does not contain a definition for returnUserType
.
The class is a public partial class Login:System.Web.UI.Page
with other functions inside and has this
public int returnUserType()
{
try
{
return userType;
}
catch
{
Response.Write("UserType failed to be returned.");
return 9;
}
}
I know I should probably be using Identity or Membership but I can't get them to run for some reason.
Create a base Page and inherit all your pages from it, so the code should look like this
public class BasePage:System.Web.UI.Page
{
public int returnUserType()
{
try
{
return userType;
}
catch
{
Response.Write("UserType failed to be returned.");
return 9;
}
}
}
public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
int userType = returnUserType();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.