Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem referencing a class!

Status
Not open for further replies.

KenniM

Programmer
Nov 27, 2002
25
0
0
DK
I have tried to find a post on this subject but haven't been able to find one that helps me!

1) I have a directory containing my .cs classes.
2) I have a codebehind file from where I want to use these classes.

?) Can I do this without compiling my classes to a dll?

I've read that you can write something like <%@ assembly=&quot;&quot; Src=&quot;&quot;%> and thats all fine but what do you do if you want to do the same but from the codebehind or from another class!

Or should I just go for the compiling method? :D
 
Hi KenniM

You need to 'import' the class into your codebehind file and then instantiate an instance of it to be able to use this. In C# you use the 'using' statement to import the class, in VB it is 'import'. Where you reference the class will depend on where they are in your web application directory. Assuming the class is in a sub directory off the root called 'components' then the syntax would be.

using namespace.components; (where namespace is the namespace for your app).

If you look at the namespace declaration in your class then this will be what you 'import'.

Then just instantiate an instance...

ClassName oClass = new ClassName();

If you are using visual studio then all of the methods and properties of your class will now be exposed by intellisense.

Hope this helps

Rob :)

------------------------------------

On with the dance! let joy be unconfined;
No sleep till morn, when Youth and Pleasure meet
To chase the glowing hours with flying feet.
-Byron

------------------------------------
 
Hi Rob, thanks for your help!

Unfortunately I can't get it to work! But maybe I'm not that far from succeeding!

More info on situation:

My files look like this:

-----------------
components (directory containing .cs class files)
default.aspx
default.aspx.cs
-----------------

all clases are inside a namespace called &quot;TaskManager&quot;!
But when i write &quot;using TaskManager.components&quot; in my default.aspx.cs file it fails! hmmm!

Maybe I'm missing something here! Do I need to register something somewhere or what??? :D







 
Also, I'm not sure what exactly is the Namespace of my app! Is it TaskManager? or is there somewhere I need to specify this! Anyone? :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top