jorame
jorame

Reputation: 2207

How to call a class in the App_Code folder from code behind?

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.

Upvotes: 1

Views: 14637

Answers (4)

Action Dan
Action Dan

Reputation: 443

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();

Upvotes: 0

saied
saied

Reputation: 21

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

Upvotes: 2

Steve Wellens
Steve Wellens

Reputation: 20620

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

Upvotes: 2

James Johnson
James Johnson

Reputation: 46047

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.

Upvotes: 6

Related Questions