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
 
G

Guest

Those are some pretty advanced questions for a newbie.

First of all, as a friendly suggestion, you might want to prioritize your
questions and post them one at a time. Even so, I find that my advanced
level web oriented questions get bypassed on this forum. That said, I will
answer one that I recently found an answer for:

This is in answer to item 3 in your post:

To the best of my knowledge, your Pages and related files should be compiled
into an exe. .Net does this automatically for a WebForms project. The
associated Controls or Class Projects compile as .dll files. I may be
missing something, but I am not familiar with running a site from just a .dll.

When you are in design mode, you can get a message box to work by doing the
following. First, add at the top of the module, under class declaration

Imports messBox = System.Windows.Forms.MessageBox

If you attempt to use MessageBox just anywhere, you will get an error. But
you can check whether Me.Site property is not nothing. If Me.Site is
instantiated, you are in design mode, and it is safe to use the message box.
You could also use debug.write, and see the results after the current debug
session in the Output Window.

www.charlesfarriersoftware.com
 
D

dotnet_vb_newbie

Charles -

Thanks for sharing that tip! It's a cool way to monitor what's
happening in Design mode. You're right about the lack of replies. I'm
not sure if it's the wrong forum, the wrong wording, the fact that the
info doesn't exist. Hopefully, one of the Microsoft MVPs will
eventually see the question and provide some guidance...
 

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

Top