|
-
Nov 8th, 2006, 02:53 PM
#1
Thread Starter
PowerPoster
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.
-
Nov 8th, 2006, 03:23 PM
#2
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.
-
Nov 8th, 2006, 03:28 PM
#3
Thread Starter
PowerPoster
Re: Global Functions in 2.0?
 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...
-
Nov 8th, 2006, 04:50 PM
#4
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:
Public Module MyMod
Public Function Test() as string
return "This Is A Test"
End Function
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|