troubleshooting Question

Howto: Access Custom Class in ASP.Net

Avatar of the_sleeper
the_sleeperFlag for United States of America asked on
.NET ProgrammingASP.NET
1 Comment1 Solution393 ViewsLast Modified:
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

// 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
Murdz

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros