1

I created a class in ASP.NET C# which is located in the App_Code folder. Now I want to call this class from my code behind from one of my .aspx pages. How can I do this?

Any help will be appreciate it.

jorame
  • 2,147
  • 12
  • 41
  • 58

4 Answers4

6

I'm assuming that you can't see the App_Code class from your code-behind, right? Go to the solution explorer and in the properties of the class, change the Build Action to Compile. After making this change, you should be able to access the class in your code-behind.

James Johnson
  • 45,496
  • 8
  • 73
  • 110
  • I'm using Microsoft Visual Web Developer 2010 Express, will this be in the same spot? – jorame Oct 21 '11 at 22:40
  • I would imagine so. In the right pane, where your project files are listed, right-click on the class under App_Code and select properties. Should be a property called "Build Action" – James Johnson Oct 21 '11 at 22:43
  • Weird, is only showing a Title of "Misc" the Custom Tool, File Name and Full Path properties. – jorame Oct 21 '11 at 22:44
2

in file of class in App_Code folder just change attribute "Build Action" to Compile

saied
  • 21
  • 2
2

After building the project to enable Intellisense, type the Namespace of the class first, or add a using statement with the Namespace.

Steve Wellens
  • 20,506
  • 2
  • 28
  • 69
0

You can access your code if you've put it in the App_Code folder. Code in there is compiled dynamically at run time, and is available for you to use anywhere, so long as your classes are public. You want to make sure you get the namespace correct. Suggest something like this:

namespace MyNamespace.App_Code {
    public class MyClass {

Then, in your code reference this using:

MyNamespace.App_Code.MyClass x = new MyNamespace.App_Code.MyClass();
Action Dan
  • 443
  • 4
  • 10