Static Method?

A

Adam J Knight

Hi all,

I have an Assembly in vs2003 (NameSpaceA), which i have made a reference to
in my current project.

This assembly contains CLASS B which is made up of utility function for
retrieving data.

I have this line in my code behind:
using NameSpaceA;

I have a server control in a page like so:
<asp:DropDownList ID="myID" DataTextField="myTextField"
DataValueField="myValueField" DataSource="<%# GetDataSource() %>"/>

My Question: How do i bridge the gap between these two items? So that the
call in the aspx page (GetDataSource), will find the method in
in NameSpaceA.

Do i simply make the methods within the class static?

Will these methods be visible, by simply having the 'using NameSpaceA'
declaration?

Some insight appreciated!!!!

Cheers,
Adam
 
K

Karl Seguin [MVP]

(a) you need to add a reference to the assembly in your web project
(b)You can import/using the namespace if you want (this only makes it so you
don' thave to fully quantify the class, which tends to make things more
readable)

if your method isn't static, you need to create a new instance of the class
and call the method


ClassB dal = new ClassB()
dal.GetUsers();


if the method is static, you can simply do:

ClassB.GetUsers();


it's hard to say whether or not it should/shoudln't be static. If the method
is truly a utility method, that it probably can/should be...your the only
one who knows enough to decide if it should or shoudln't be, but either way
it should be easy to do.

Karl
 
K

Kris

Hi Adam,

You have to import the namespace in your aspx file. You can do this as
shown below.

<%@ Import Namespace="NameSpaceA" %>

Hope this would help you.

Cheers,
Kris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top