Search code examples
c#functionclasscontrolspageload

How do you access a function in Page_Load


This question is like Cannot access Public method in Web Control's Page_Load event

However since you are not allowed to ask questions inside someone else's question I'm making a new question.

I have the following layout:

namepspace
{
    public partial class
    {

    protected void Page_Load
    { 
    }

    class Employee
    {

        public static bool employeeType
        {
        }
    }
}

If I want to access employeeType in Page_Load, how can I access it?


Solution

  • This

    protected void Page_Load
    {
        // We can access whitout creating a instance since it is static
        Employee.employeeType
    }
    

    Doesn't work? Also, what exactly is employeeType? If it is a function:

    protected void Page_Load
    {
         Employee.employeeType();
    }
    

    But then you are missing the parenthesis and the return type on the declaration. You should declare like this, preferably starting with uppercase (call it with uppercase also):

    class Employee
    {
        public static void EmployeeType()
        {
    
        }
        ....
    }
    

    Edit

    So, it is a static property. Then:

    protected void Page_Load
    {
         bool type = Employee.EmployeeType;
    }
    
    class Employee
    {
        public static bool EmployeeType
        {
            get { return true; }  // Your logic here...
        }
        ....
    }