Hi, I am having a problem with instantiating two custom objects so they
DO NOT point to the same memory location. What is happening is that
changes I am making to my object1 are changing object2. I beleive this
is because I set both to be equal to the same session variable. So when
I change the value in test1.name it updates test2.name as well as the
session variable itself. What I want to do is keep an "ORIGINAL" copy
of the data in case I want to rollback. Can anyone explain this to me?
Thanks.
CODE SAMPLE:
CUSTOM OBJECT-
Public Class test
Private _aName As String = ""
Property aName() As String
Get
Return _aName
End Get
Set(ByVal Value As String)
_aName = Value
End Set
End Property
Public Sub New()
End Sub
End Class
CODE BEHIND PAGE1-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As New TestSession.test
x.aName = "TestOrg"
Session("test") = x
Response.Redirect("WebForm1.aspx")
End Sub
CODE BEHIND PAGE2-
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
process()
End If
End Sub
Private Sub process()
Dim test1 As New TestSession.test
test1 = CType(Session("test"), TestSession.test)
Dim test2 As New TestSession.test
test2 = CType(Session("test"), TestSession.test)
test1.aName = "TestChange"
Me.TextBox1.Text = test1.aName
Me.TextBox2.Text = test2.aName
End Sub
Text boxes both display TestChange instead of one with TestChange and
one with TestOrg