Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session object access in modules

Status
Not open for further replies.

rotsey

Programmer
Nov 23, 2004
135
AU
Hi,

How do get access to the Session object when writing code in a module

I want to call a function and pass variables and assign to Session object

Session("myVar") = var
Do i have to set a Imports statement. What class?

rotsey
 
You don't have access to the session object so when you write your function pass the session value through to the function as an argument.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
cool thanks

but how do I declare the variable in the function

Public Sub InitialiseApp(ByVal acc As cAccount, ByVal Session As ??????)

I looked but could not find it??


rotsey
 
You don't declare it as a session object. It is whatever type you want to pass through. e.g.

In your function
Code:
    Public Sub MySub(ByVal MyString As String)
        ' Do Stuff
    End Sub

and you call it from your page like:
Code:
Dim tempClass as New MyClass
tempClass.MySub(Session("Here is my string"))


----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
no I wanted to pass the Session object through to the function.

So I declared it as type Object and that worked.

Thanks for your help.
 
Why do you want to pass the whole session object? That is just creating massive overheads as every session will be duplicated whenever one of the functions is called and will have a big impact on memory. You should only pass the session variables you want to work with.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
well I have logon code that runs in a user control and also I waant to run the same logon code in Login page. So I created a function in a module to assign my variables to the Session object.

I want to assign variables to Session variables.

But I take your point.

 
Presumably you only need the username & password variables in order to run your login code so I would suggest creating a function in your module that accepts these two as parameters. You then only need to pass those two session variables through as opposed to the whole object.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
ca8msm is completely right, you shouldn't be passing your session around. However, I just thought I'd add that all objects (such as Session) are passed by reference regardless of whether you pass them byval or byref, so it wouldn't create new copies of the session. The real reason not to is that it's poor coding form.
 
I have to first validate the user then I want to load some variables used in the app and i want to store them in Session.

I have 2 places where they can logon the Login.aspx and also code in each page includes a user control that does validation checks using User property. So to assign my variables I created a function called InitApp that I want to initialise in Session state.

here is some code

Code:
   Public Sub InitialiseApp(ByVal acc As cAccount, ByVal Session As Object)

        Dim cdata As New cCourseData

        Session("UserAccID") = acc.AccID
        Session("UserID") = acc.UserID
        Session("UseNicknames") = acc.UserNicknames
        Session("NoExcludedRounds") = acc.UserNoExcludedRounds
        Session("UserReadOnly") = acc.UserReadOnly
        Session("CalcStableford") = acc.UserCalcStableford
        cdata.AccID = acc.AccID
        If cdata.LoadCourses Then
            Session("CourseData") = cdata.BuildCourseStr
        End If

    End Sub

So this is called 2 places.

how do I initialise those session variables???

rostey
 
dace - you are indeed correct. I assumed another object would be created but that is not the case. Thanks for the correction.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top