global functions?

  • Thread starter Thread starter Chattanooga
  • Start date Start date
C

Chattanooga

hi all

just a quick one, where can i put functions that all asp.net pages
within an application can call? i tried globla.asax.vb, but that did
not work.

TIA!!!

Chris
 
Go for a base page(a simple aspx page), which holds the common
functions
namespace yournamespace

public class yourclass :basepage // instead of yourclass :
System.Web.UI.Page
{


}

while loading the page it will load the common function from the base
page.
 
i am sorry, i do not follow, could you pack that into a very small
example of what to put in what file, or point me to a link?

thanks a lot!!

regards,
Chris
 
Personally i make functions for any global activity in a separate project
and then compile to make the dll. Then add the resulting DLL as a reference
in your projects that you want to use them.

that way you can build up a complete class library that is separate from the
sub projects that use it without the need for a global aspx page holding
them all.
 
If you use ASP.NET 2.0 you can add an app_code folder and add a class
to this folder

HTH
 
Personally i make functions for any global activity in a separate project
and then compile to make the dll. Then add the resulting DLL as a reference
in your projects that you want to use them.

that way you can build up a complete class library that is separate from the
sub projects that use it without the need for a global aspx page holding
them all.

hi,

thanks for the hint, is there a link that describes this process in
any detail?

tia,
Christian
 
It's not shown in the dialog but you can create modules as in VB6.
Simply add a class module, rename CLASS for Module (+ end module : ) )
Each function in the module is now public.

O well, this might be slightly different in c though.
 
I think the other responses are tyring to make things more complex. Many
refer to the physical location such as another DLL or the app_code folder.

Really, just make another class and create static methods.

public class Utilities{
public static MethOne(){
}

public static MethTwo(){
}
}

Then you can call the methods from anywhere by invoking Utilities.MethOne()
and so on.
 
Sorry dont know any but it is really simple.

Basically, start a new web app as you would normally.

Code your classes that you want everything to have access to, set to release
mode and compile.

The bin directory will hold a dll file. That dll file is the compiled
dynamic link library of those classes.

Now to include that dll go to your main project and on the right pane it
says references.

Right clik on that and i think it says add reference or something similar.
Choose this.

Now in the subsequent window browse for the dll and select it, say ok and
voila it has been added as a reference (i believe it also copies the dll
into your bin app of your current application for you as well but dont quote
me on that)

Now say your dll had a class in it in a namespace called yourNamespace and a
class called MyClass. You simply add this at the top of your page:

using yourNamespace;

and in your code you can put:

MyClass _myObj = new MyClass();

And access it as usual.

Hope that is all clear, i wrote this from memory so i hope i havent missed
any steps, failry self explanatory. Very neat way of adding global code and
in my opinion the way to do it.
 

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

Back
Top