473,788 Members | 2,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.writelin e 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("Dat aFile.soap", FileMode.Create )
Try
sf.Serialize(fs , htTextProps)
Catch e As SerializationEx ception
Debug.WriteLine ("Failed to serialize. Reason: " &
e.Message)
Throw
Finally
fs.Close()
End Try
Return htTextProps
End Function

Public Overridable Sub LoadViewState(B yVal savedState As Object)
HttpContext.Cur rent.Trace.Warn ("LoadViewState ()", "Loading the
view state...")

If Not (savedState Is Nothing) Then
Dim fs As New FileStream("Dat aFile.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(form atter.Deseriali ze(fs),
Hashtable)
Catch e As SerializationEx ception
HttpContext.Cur rent.Trace.Warn ("Failed to deserialize.
Reason: ", e.Message)
Throw
Finally
fs.Close()
End Try
End If
End Sub

Nov 21 '05 #1
2 2041
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.MessageBo x

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.n et" 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.writelin e 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("Dat aFile.soap", FileMode.Create )
Try
sf.Serialize(fs , htTextProps)
Catch e As SerializationEx ception
Debug.WriteLine ("Failed to serialize. Reason: " &
e.Message)
Throw
Finally
fs.Close()
End Try
Return htTextProps
End Function

Public Overridable Sub LoadViewState(B yVal savedState As Object)
HttpContext.Cur rent.Trace.Warn ("LoadViewState ()", "Loading the
view state...")

If Not (savedState Is Nothing) Then
Dim fs As New FileStream("Dat aFile.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(form atter.Deseriali ze(fs),
Hashtable)
Catch e As SerializationEx ception
HttpContext.Cur rent.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
3722
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 into session. The Error message shows like ---------------------------------------------------------------------------- ----- Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not...
3
1392
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? viewstate??? sessions? or database in each "next" click???
13
5259
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 structures? Thanks for any hints, Leszek Taratuta
4
1850
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 everytime a logged in user hits a page. So far, it works great. Here is my question, is my approach for storing logged in users correct? Meaning, can I be sure that only one instance of my IHttpModule will be created for my Application. So...
0
371
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 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...
0
3603
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 have individual settings for each page. I decided to hold them in a collection. I started out with a generic Dictionary but that didn't work. So, I created a new Forms app to test it out and created a Settings file. It didn't offer me the...
1
3735
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 database file throu GUI Save Record button? As i write the comand as foloow but it is not inserting the new record in to the Access Database. Public Function Open_Connection() As Boolean Try Select Case...
8
1847
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 different way. This way (and ocz there are other ways) I don't have to user different parameter to call a method or invent an other global data repository. Regards,
0
1005
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 is our web server or sql server (2000). I noticed that the app uses cache (with sql server 2000) and Session States. I compiled a list of what was in cache and session state and wondered if you could give me your opinion on it. Is it a lot? ...
1
1163
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 is our web server or sql server (2000). I noticed that the app uses cache (with sql server 2000) and Session States. I compiled a list of what was in cache and session state and wondered if you could give me your opinion on it. Is it a lot? ...
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10364
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.