473,320 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to save state on a HashTable?

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

Nov 21 '05 #1
2 2005
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

"do**************@programmer.net" wrote:
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

Nov 21 '05 #2
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...

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bill L | last post by:
Hi guys, Because of restarting application after new DLLs installed into \Bin folder , we move the session to StateServer, everything'a alright except when I try to write any simple hash table...
3
by: Tobias[br] | last post by:
hi there people... i´m developing an application where i need 190 input text, in 8 diferent forms.. anyone can tell me the best pratice to save the the data while edit the others forms?...
13
by: Leszek Taratuta | last post by:
Hello, I have several drop-down lists on my ASP.NET page. I need to keep data sources of these lists in Session State. What would be the most effective method to serialize this kind of data...
4
by: Mike | last post by:
I've created a custom IHttpModule that does custom authentication. Currently it stores authenticated user info in a hashtable within the class so I don't have to re-authenticate against a database...
0
by: dotnet_vb_newbie | last post by:
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...
0
by: ssg31415926 | last post by:
I've been trying to save a hashtable in an Application Settings file. I need to save settings for each tabPage on a form. Trouble is, the number of tabPages is determined at runtime, so I can't...
1
by: Rameel | last post by:
Friends, I'm probably being more critical with VB.Net Windows application. I have Developed VisualStudio 20005 VB.Net Windows application how willl i be able to save a specific record into my...
8
by: Ryan Liu | last post by:
Is that a good idea to add a Hashtable to System.Windows.Forms.Application class? And we can put any user global data in it. I have some class library used by a few other applications in slight...
0
by: dities13 | last post by:
Hello all and thank you for your time. We have a 3rd party application written for my office (vb.net 2.0 framework). However, we are getting reports of slow response time and do not believe it...
1
by: dities13 | last post by:
Hello all and thank you for your time. We have a 3rd party application written for my office (vb.net 2.0 framework). However, we are getting reports of slow response time and do not believe it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.