I am having a peculiar issue:
I am saving an object in my code behind (VB.NET) for a page as below:
<asp:CheckBox ID="cbAddress" runat="server" Text="Check for Address Information" Checked="false"/>
'Code in the program
Dim cbAddress As CheckBox = DirectCast(uclAddressInformation.FindControl("cbAddress"), CheckBox)
'Function to SAVE/SET session
Private Sub SetCheckBoxToSession(ByVal name As String, ByVal chk As CheckBox)
HttpContext.Current.Session.Add(name, chk )
'Function to GET session
Private Function GetCheckBoxFromSession(ByVal name As String) As CheckBox
Dim chk As New CheckBox
Dim objChk As Object = HttpContext.Current.Session(key)
If Not (objChk Is Nothing) Then
chk = CType(objChk, CheckBox)
But when I read the session, after the checkbox is updated, the session value is also updated for Checkbox.Visible property. So it means that the session is storing a pointer to the object.
Is there any way to make snapshot of the object and then store the value in the session, so that the change in the object does not affect the session.
Note: I could have stored static values in the session that don't change, but I want to store the entire object.