How to save state on a HashTable?

  • Thread starter dotnet_vb_newbie
  • Start date
D

dotnet_vb_newbie

I've developed a provider in VB which extends all textbox controls on a
webform. The attributes for all the textbox objects are saved in a
HashTable. I'm having a problem figuring out the right way to save the
hashtable's state.
I've listed the code below. I have a number of questions:

1) Is this a reasonable approach to saving the hashtable state?
2) Is there anything inherrently unsecure about saving the state in a
file?
3) The code is compiled into a DLL. In general, is there a way to have
the DLL output error or informational messages when under testing?
(debug.writeline and HttpContext don't seem to work)
4) Do I actually have to call the SaveViewState or LoadViewState
functions in my code, or is overriding the functions sufficient for the
state to persist?
5) If I set any of the textBox attributes, close the .ASPX file, and
then reopen the .ASPX file, all the attributes get reset to defaults.
Is that a persistence issue which will be resolved when I get the right
coding?
6) Is it possible to get the AddHandler calls (textChange) to persist?

Thanks in advance for any help and or pointers you can provide! Code
follows:

Public Overridable Function SaveViewState() As Object
Dim sf As New SoapFormatter
Dim fs As New FileStream("DataFile.soap", FileMode.Create)
Try
sf.Serialize(fs, htTextProps)
Catch e As SerializationException
Debug.WriteLine("Failed to serialize. Reason: " &
e.Message)
Throw
Finally
fs.Close()
End Try
Return htTextProps
End Function

Public Overridable Sub LoadViewState(ByVal savedState As Object)
HttpContext.Current.Trace.Warn("LoadViewState()", "Loading the
view state...")

If Not (savedState Is Nothing) Then
Dim fs As New FileStream("DataFile.soap", FileMode.Open)
Try
Dim formatter As New SoapFormatter

' Deserialize the hashtable from the file and
' assign the reference to the local variable.
savedState = DirectCast(formatter.Deserialize(fs),
Hashtable)
Catch e As SerializationException
HttpContext.Current.Trace.Warn("Failed to deserialize.
Reason: ", e.Message)
Throw
Finally
fs.Close()
End Try
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top