Results 1 to 4 of 4

Thread: Global Functions in 2.0?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Question Global Functions in 2.0?

    I have many webpages that need access to the same function call returning me the currently logged in user. How can I place this code globally so that all webpages can take advantage of this code and prevent me from copying and pasting this to all my pages?

    Code:
    'Collection of users in the membership.
    
    Dim MemberColl As MembershipUserCollection
    
    'Finds the user based on the email.
    
    MemberColl = Membership.FindUsersByName(sender.username)
    
    'Enables you to iterate over the collection.
    
    Dim Enumerator As IEnumerator
    
    Enumerator = MemberColl.GetEnumerator
    
    'Needed even get to the first record in the collection.
    
    Enumerator.MoveNext()
    
    Dim MemUser As MembershipUser
    
    'Get the user.
    
    MemUser = Enumerator.Current
    Last edited by jesus4u; Nov 8th, 2006 at 03:04 PM.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Global Functions in 2.0?

    put it in a module and make the method public, or put it in a class and make the method shared. That will give you access to it from anywhere in the application.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: Global Functions in 2.0?

    Quote Originally Posted by kleinma
    put it in a module and make the method public, or put it in a class and make the method shared. That will give you access to it from anywhere in the application.
    umm..I don't see the ability to add a module to a web app?

    A class won't work here for I am using the Membership Collection...

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Global Functions in 2.0?

    Just add a class .vb file to your web app and change the word Class to Module in the code

    VB Code:
    1. Public Module MyMod
    2.     Public Function Test() as string
    3.         return "This Is A Test"
    4.     End Function
    5. End Module

    Then in your aspx code behind page for any given page, you can simply call MyMod.Test and it will return that string.

    As for what you said about using the membership collection. I don't know what that has to do with you using or not using a module/class. Infact a module simply is a class, where everything is automatically shared. Do you mean because you need some value that is on the ASPX page at runtime? If so you can simply pass it to your function in your module/class and process it.

Posting Permissions

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



Click Here to Expand Forum to Full Width