Groups | Blog | Home
all groups > asp.net > february 2006 >

asp.net : Static Method?


Karl Seguin [MVP]
2/14/2006 8:58:17 AM
(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
--
http://www.openmymind.net/
http://www.fuelindustries.com/


[quoted text, click to view]

Kris
2/14/2006 11:40:29 AM
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
Adam J Knight
2/14/2006 11:35:35 PM
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

AddThis Social Bookmark Button