Hi,
You can use class files surely to achieve the same. So if you are using
vb, you will have a file like class1.
vb which will be placed in the app_code folder of the application.
Let me write a code for you to help you clear than giving cryptic codes as answers:)
Three files in the project used below are:
Default.aspx, default.aspx.
vb and class1.
vb (in app_code folder)
default.aspx - has a button (button1) and a textbox (text1)
default.aspx.vb file will have the following code for page_load and button click
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
HttpContext.Current.Session("session_a") = "Vincent"
HttpContext.Current.Session("session_b") = "Thomas"
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim seschk As New Class1
Dim sess_string As String
sess_string = seschk.abc()
Text1.Text = sess_string
End Sub
End Class
While
class1.vb, the class file will have the following code.
Imports Microsoft.VisualBasic
Public Class Class1
Public Function abc() As String
Dim xStr As String = ""
xStr = xStr & HttpContext.Current.Session("session_a") & " "
xStr = xStr & HttpContext.Current.Session("session_b")
Return xStr
End Function
End Class
I have set the sesssion variables in the page load of the form itself, however you can set it anywhere in any form.
Dim seschk As New Class1 - this code is required to create an instance of the class created in Class1.
vb file. You can use the above code to create as many objects in multiple aspx file and use the functions present in class1.
vb
Hope this helps, post back if you need further assistance.
Vincent Thomas
Bangalore