|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
global functions?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. On 13 Jan 2006 01:50:15 -0800, "MSEN" <mailm***@gmail.com> wrote: i am sorry, i do not follow, could you pack that into a very smallexample of what to put in what file, or point me to a link? thanks a lot!! regards, Chris Show quoteHide quote >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. 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. -- Show quoteHide quoteDan "Chattanooga" <ro***@gmx.at> wrote in message news:etses1tbunbj121c7crffh1q23b9ponm5b@4ax.com... > 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 On Fri, 13 Jan 2006 10:52:43 -0000, "Dan" <dvazan***@aol.com> wrote: hi,>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. thanks for the hint, is there a link that describes this process in any detail? tia, Christian 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. -- Show quoteHide quoteDan "Chattanooga" <ro***@gmx.at> wrote in message news:pe4fs11ftam2nu3ne2hh1eh30ekjf45s1l@4ax.com... > On Fri, 13 Jan 2006 10:52:43 -0000, "Dan" <dvazan***@aol.com> wrote: > >>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 If you use ASP.NET 2.0 you can add an app_code folder and add a class
to this folder HTH ----------------------------------------- David Gray ASP.NET/C# Developer/Architect (MCAD.NET) On Fri, 13 Jan 2006 09:36:00 GMT, Chattanooga <ro***@gmx.at> wrote: Show quoteHide quote >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 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. Show quoteHide quote "Chattanooga" <ro***@gmx.at> schreef in bericht news:etses1tbunbj121c7crffh1q23b9ponm5b@4ax.com... > 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 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. Show quoteHide quote "Chattanooga" <ro***@gmx.at> wrote in message news:etses1tbunbj121c7crffh1q23b9ponm5b@4ax.com... > 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
Other interesting topics
Basic question about database connection in ASP.NET
Why so much trouble with ellipses? File Download Seeking examples of screen scraping.... Issue with ASP.NET 2.0 Global asax FormsAuthentication.SignOut() and User.Identity reference to a "global" variable from within an aspx page 3-Tier Binding Problem ????????? Website config tool asp.net 2.0 Inserting a default ListItem in DropDownList Control |
|||||||||||||||||||||||