【问题标题】:Cannot see employee class object properties in asp.net在 asp.net 中看不到员工类对象属性
【发布时间】:2012-07-05 17:37:16
【问题描述】:

我有一个从“Login.aspx”页面的 btnContinue_Click 事件调用的 Employee 类对象。我无法看到智能感知中的任何属性。 Employee.cs 文件与 Web 应用程序位于同一项目中。让我感到困惑的是,aspx.cs 可以很好地识别Employee oEmp = new Employee();

我在下面的代码中做错了什么?

这是我的代码:
employee.cs

public class Employee
{
    public string FirstName  { get; set; }
    public string LastName { get; set; }
    public string DateOfBirth { get; set; }
    public string EMailAddress { get; set; }
    public string PhoneNumber { get; set; }
    public string CorpID { get; set; }
    public string SignOn { get; set; }
    public string Password { get; set; }
}  

Login.aspx.cs

    protected void btnEmployeeLogin_Click(object sender, EventArgs e)
    {
        try
        {
            if (LogInValidated())
            {
                Employee oEmp = new Employee();
                //oEmp.
            }
        }

        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }

【问题讨论】:

  • 愚蠢的问题,但无论如何。 Employee 类是在某个特定的命名空间中创建的吗?你是 using 那个命名空间吗?
  • 您的页面中是否包含具有相同类的任何其他命名空间?在这种情况下,您可能正在创建另一个类的对象
  • Employee 类与 aspx 文件在同一个命名空间中
  • 看来你也有Employee作为UserControl
  • 查看@Mark Rucker 的更新答案。

标签: c# asp.net oop intellisense


【解决方案1】:

听起来 Visual Studios 认为 oEmp 是 .aspx 页面上的控件,而不是 Employee 类的类型。您是否仔细检查了您的 .aspx 页面,以确保您没有带有 ID="oEmp"runat="server" 的控件?

或者您确定您的解决方案中没有Employee.ascx 文件?

【讨论】:

    【解决方案2】:

    在页面顶部,您可以添加:

    using **here the package of your employee class**;
    

    【讨论】:

    • using 语句不应包含类名,仅用于命名空间
    【解决方案3】:

    确保 Customer 类与 btnCustomerLogin_Click 事件位于同一命名空间中。如果它没有在类的顶部包含 using 语句。

    如果您使用的是 Visual Studio,只需单击 Employee 对象并按 Ctrl+'。' 并从那里选择命名空间。

    【讨论】:

      【解决方案4】:

      移动 Employee.cs 文件,使其位于 App_Code 下。这应该让 VS 识别类。

      如果您还没有 App_Code 文件夹,请通过以下方式添加:

      • 在 VS 解决方案资源管理器中右键单击网站
      • 在“Add Asp.net folder”下选择“App_Code

      不要只添加一个名为 App_Code 的“常规”文件夹。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-27
        • 1970-01-01
        • 2019-08-21
        • 2018-04-04
        • 1970-01-01
        • 1970-01-01
        • 2012-04-28
        • 1970-01-01
        相关资源
        最近更新 更多