简体   繁体   中英

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.

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.

在App_Code文件夹中的类文件中,只需将属性“ Build Action”更改为Compile

生成启用Intellisense的项目后,请首先键入该类的名称空间,或在名称空间中添加using语句。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM