473,387 Members | 1,398 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,387 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 2012
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.