質問

I can't use a simple class in aspx.cs file. I know i should include some code to declare this class before creating an instance like

User user = new User();

, but I don't know the syntax. I'm new to C# and ASP.net, as you see, and can have other errors in logic so any help is appreciated

This is how my website structure looks like:

This is how my website structure looks like

This is the code of User.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


public class User
{

  public int Id 
  {
    get { return id; }
    set { id = value; } 
  }

  public String Username
  {
    get { return username; }
    set { username = value; }
  }

  public String Password
  {
    get { return password; }
    set { password = value; }
  }

}

This is the code of Default.aspx.cs:

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      if(!IsPostBack)
      {
        doSomething();
      }
    }

    private void doSomething() {
      User user = new User(); // error is shown
    }
}
役に立ちましたか?

解決

use ctr+. placing cursor in the user and you will get help on that.

Edit 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DBConnection.model.business
{
    public class User
    {
    ...

Then using like below in your default.aspx

using DBConnection.model.business;

You can get the reference of your class.

他のヒント

Add using DBConnection.model.business;

or

  1. Point user object and click mouse right click
  2. Select resolve
  3. enter image description here
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top