I am new to asp.net and i am trying to solve a problem.
I have created a simple aspx page (asp web site) that references a vb.net class. I am handling one class instance using the session context object (don't know if there is a better way). The class has a sub that sets a string value and a function that returns it.
I compile and run the web site project and then set the value "1" from one aspx page and the value "2" from another page (i open a second tab or browser by copying-paste the url from the first page) and then retrieve the values, both pages will show "2".
The same class in a vb.net form application (.exe) works just fine when the exe instances are running, the first returns the value "1" and the second the value "2". This is how i want it to work in my web site project, different pages different dll instances.
Class:
Public Class Class1
Private sExten As String
Public Sub setExten(value As String)
sExten = value
End Sub
Public Function getExten() As String
Return sExten
End Function
End Class
aspx:
Partial Class _Default
Inherits System.Web.UI.Page
'trying to ensure one instance is running
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Session.Add("ClassLibrary1", New ClassLibrary1.Class1)
End If
End Sub
'txtSetValue.text contains value "1" or "2"
Protected Sub btnSet_Click(sender As Object, e As EventArgs) Handles btnSet.Click
CType(Session.Item("ClassLibrary1"), ClassLibrary1.Class1).setExten(txtSetValue.text)
End Sub
'the txtShowValue shows "1" in the first and "2" in the second page
Protected Sub BtnGet_Click(sender As Object, e As EventArgs) Handles BtnGet.Click
txtShowValue.Text = CType(Session.Item("ClassLibrary1"), ClassLibrary1.Class1).getExten()
End Sub
End Class