Import a class in ASP.NET

末鹿安然 提交于 2021-02-08 13:14:25

问题


I want to import a class that is in App_Code to use it in my aspx pages.

How can I do it ?

Thanks


回答1:


Add the namespace you used to your codebehind file or aspx file(if not using code behind).

using YourNamespace; //C#
imports YourNamespace //VB

or if not using codebehind

<%@ Import Namespace="YourNamespace" %>  



回答2:


if your app_code class is in another namespace, add a using statement at the top of your code behind. Example:

using MyCustomNamespace;

EDIT: if using vb in your code behind:

imports MyCustomNamespace



回答3:


If you didn't add a Namespace clause in your class you won't need to import anything, you can use the class directly from code behind.

If you have a Namespace clause in the class, just add "Imports YourNamespaceName" in the first line of your code behind.



来源:https://stackoverflow.com/questions/2921207/import-a-class-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!