Farmer
Farmer

Reputation: 10983

Import a class in ASP.NET

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

How can I do it ?

Thanks

Upvotes: 8

Views: 44297

Answers (3)

ACB
ACB

Reputation: 1000

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.

Upvotes: 0

sclarson
sclarson

Reputation: 4422

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" %>  

Upvotes: 21

derek
derek

Reputation: 4886

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

Upvotes: 0

Related Questions