Professional Web Applications Themes

How to create global Funtions & Routines - ASP.NET General

I'm at a loss on how to create global functions for my website. Essentially, I have several different functions I use throughout my site and I want to be able to put these in 1 file and call them from anywhere. Currently, I just copy them into each aspx file... Not what I want to do. Any help? BTW, I am using WebMatrix to develope the aspx forms. TIA -Matt...

  1. #1

    Default How to create global Funtions & Routines

    I'm at a loss on how to create global functions for my website.
    Essentially, I have several different functions I use throughout my site and
    I want to be able to put these in 1 file and call them from anywhere.
    Currently, I just copy them into each aspx file... Not what I want to do.

    Any help? BTW, I am using WebMatrix to develope the aspx forms.
    TIA
    -Matt


    Matthew Hood Guest

  2. #2

    Default Re: How to create global Funtions & Routines

    Welcome to object oriented programming. ;o)

    Each page in your site is a class. You'll note at the top of your
    codebehind file (I'm assuming you have this in webmatrix?) that you specifiy
    a class name for your page... e.g. "Public Class myPage"... this "page" is a
    public class, so it is available to any part of your application. (Assuming
    it exposes the methods you need).

    Lets assume you have a function in your codebehind file that you want to
    access elsewhere in your web application. You can just create an instance
    of the other "page" (class) from within your current codebehind file by
    just stating:

    dim myTool as new myPage()

    where myPage is the class that contains the method you wish to use. For
    example if you had a function that added two numbers in your myPage class
    called "addIt" you could say:

    dim myTool as new myPage()
    dim myresult as Integer = myTool.addIt(number1, number2)

    What you really need to do is have a class library. (just a file with a .vb
    extension) in you application with the classes you wish to implement
    globally, that way when you create an instance of the "tool" you need you
    aren't using all the extra memory neccessary to create an instance of the
    myPage class. (because it inherits from the Page class which has a ton of
    methods, etc..)

    Hope that helps.

    -MC D


    "Matthew Hood" <mshoodqwest.net> wrote in message
    news:uoU6kcpODHA.3020TK2MSFTNGP10.phx.gbl...
    > I'm at a loss on how to create global functions for my website.
    > Essentially, I have several different functions I use throughout my site
    and
    > I want to be able to put these in 1 file and call them from anywhere.
    > Currently, I just copy them into each aspx file... Not what I want to do.
    >
    > Any help? BTW, I am using WebMatrix to develope the aspx forms.
    > TIA
    > -Matt
    >
    >

    MC D Guest

  3. #3

    Default Re: How to create global Funtions & Routines

    Webmatrix does not use the Codebehind method.
    Initially I created the functions in a .vb file, but when I tried to access
    them from a page, I get an error stating that the routines were not defined.
    Do the vb files have to be compiled?

    TIA-
    Matt

    "MC D" <nospamearthtalk.com> wrote in message
    news:vfi9po4kc9np5ccorp.supernews.com...
    > Welcome to object oriented programming. ;o)
    >
    > Each page in your site is a class. You'll note at the top of your
    > codebehind file (I'm assuming you have this in webmatrix?) that you
    specifiy
    > a class name for your page... e.g. "Public Class myPage"... this "page" is
    a
    > public class, so it is available to any part of your application.
    (Assuming
    > it exposes the methods you need).
    >
    > Lets assume you have a function in your codebehind file that you want to
    > access elsewhere in your web application. You can just create an instance
    > of the other "page" (class) from within your current codebehind file by
    > just stating:
    >
    > dim myTool as new myPage()
    >
    > where myPage is the class that contains the method you wish to use. For
    > example if you had a function that added two numbers in your myPage class
    > called "addIt" you could say:
    >
    > dim myTool as new myPage()
    > dim myresult as Integer = myTool.addIt(number1, number2)
    >
    > What you really need to do is have a class library. (just a file with a
    ..vb
    > extension) in you application with the classes you wish to implement
    > globally, that way when you create an instance of the "tool" you need you
    > aren't using all the extra memory neccessary to create an instance of the
    > myPage class. (because it inherits from the Page class which has a ton of
    > methods, etc..)
    >
    > Hope that helps.
    >
    > -MC D
    >
    >
    > "Matthew Hood" <mshoodqwest.net> wrote in message
    > news:uoU6kcpODHA.3020TK2MSFTNGP10.phx.gbl...
    > > I'm at a loss on how to create global functions for my website.
    > > Essentially, I have several different functions I use throughout my site
    > and
    > > I want to be able to put these in 1 file and call them from anywhere.
    > > Currently, I just copy them into each aspx file... Not what I want to
    do.
    > >
    > > Any help? BTW, I am using WebMatrix to develope the aspx forms.
    > > TIA
    > > -Matt
    > >
    > >
    >
    >

    Matthew Hood Guest

Similar Threads

  1. Replies: 0
    Last Post: March 29th, 11:28 PM
  2. Calling on Visual Basic funtions
    By Eva in forum ASP Components
    Replies: 0
    Last Post: February 19th, 09:05 PM
  3. OCR funtions in Acrobat 7 SDK
    By Geoff_Ch@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 1
    Last Post: August 7th, 07:13 PM
  4. Wizards to create table maintainance routines?
    By DukeLA in forum Coldfusion - Getting Started
    Replies: 0
    Last Post: February 18th, 06:27 PM
  5. IBM AIX 5.1 routines
    By dorth in forum AIX
    Replies: 2
    Last Post: September 30th, 01:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139