Results 1 to 4 of 4

Thread: Global Functions in 2.0?

  1. #1
    PowerPoster
    Join Date
    Jan 01
    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 02:04 PM.

  2. #2
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 01
    Location
    NJ - USA (Near NYC)
    Posts
    23,021

    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.
    Using VB.NET 2010/.NET 2.0 through 4.0 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  3. #3
    PowerPoster
    Join Date
    Jan 01
    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
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 01
    Location
    NJ - USA (Near NYC)
    Posts
    23,021

    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.
    Using VB.NET 2010/.NET 2.0 through 4.0 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

Posting Permissions

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