the_sleeper
asked on
Howto: Access Custom Class in ASP.Net
C# Noob Here,
Having problems attaching a custom class to my pages
1. I created A custom "Car" class (Car.cs)
2. I created an App_Code folder and placed Car.cs in there.
3. I called the class from my default.aspx.cs page
4. Where I promptly got the following error:
The type or namespace name 'Car' could not be found (are you missing a using directive or an assembly reference?)
I also noticed that the namespace in the class has a .App_Code attached to it. Tried removing it - no difference.
Please advise
Having problems attaching a custom class to my pages
1. I created A custom "Car" class (Car.cs)
2. I created an App_Code folder and placed Car.cs in there.
3. I called the class from my default.aspx.cs page
4. Where I promptly got the following error:
The type or namespace name 'Car' could not be found (are you missing a using directive or an assembly reference?)
I also noticed that the namespace in the class has a .App_Code attached to it. Tried removing it - no difference.
Please advise
// Car.cs (in App_Code folder)
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace sti_v00.App_Code
{
public class Car
{
// fields
private string _make;
private string _model;
private int _year;
private int _elapsedMiles;
// set properties
public string make
{
get { return _make; }
set { _make = value; }
}
public string model
{
get { return _model; }
set { _model = value; }
}
public int year
{
get { return _year; }
set { _year = value; }
}
public int elapsedMiles
{
get { return _elapsedMiles; }
set { _elapsedMiles = value; }
}
// create method
public int updateMileage(int miles)
{
int theResult = _elapsedMileage += miles;
return theResult;
}
}
}
/*
* Default.aspx.cs
*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace sti_v00
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Car myCar = new Car();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.