473,387 Members | 1,545 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.

Storing a hash table in Session

Hi
I am creating a sign-up process on a web site much like that of a
wizard form. I have browsed many sites to look for examples of how to
store the entry data, so that the user can go back and forward along
the sign -up process. I am currently trying to use a Session object to
store all these details and get them back out of session as each step
is selected.

My model was a HashTable of NameValueCollection, so I could go to the
hash for the particular step, and get the name key value pairs of each
data.

My problem is when I go to recollect the session object (Effectively a
hash table). The object has no data, ie Hash count items = 0. however
when I store this hash table to the Session object it has 5 or 6 items
..

There is something obviously happening when the object is being stored,
maybe a serialization issue.. I am new to this development so would
appreciate any pointers that people may have, or another technique I
can use? Perhaps NameValueCollection or HashTable cant be stored in
session? but why then are they serilaizable?

Many thanks

Richard

Feb 17 '06 #1
8 9426
Richard,

If it was a serialization issue, then you would get an error, you
wouldn't just have the session drop like that.

Are you sure you have sessions enabled (through cookies, or cookieless)?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<rg*******@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi
I am creating a sign-up process on a web site much like that of a
wizard form. I have browsed many sites to look for examples of how to
store the entry data, so that the user can go back and forward along
the sign -up process. I am currently trying to use a Session object to
store all these details and get them back out of session as each step
is selected.

My model was a HashTable of NameValueCollection, so I could go to the
hash for the particular step, and get the name key value pairs of each
data.

My problem is when I go to recollect the session object (Effectively a
hash table). The object has no data, ie Hash count items = 0. however
when I store this hash table to the Session object it has 5 or 6 items
.

There is something obviously happening when the object is being stored,
maybe a serialization issue.. I am new to this development so would
appreciate any pointers that people may have, or another technique I
can use? Perhaps NameValueCollection or HashTable cant be stored in
session? but why then are they serilaizable?

Many thanks

Richard

Feb 17 '06 #2
Hi Nicholas,

Many thanks for your reply..Below is my sessionState node from my
config file

Rich

<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data
source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>

Feb 17 '06 #3
Richard,
Could you post a "Short but Complete" code example of how you are populating
your "Hashtable-like" object, storing in Session, then retrieving from
Session?

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"rg*******@hotmail.com" wrote:
Hi
I am creating a sign-up process on a web site much like that of a
wizard form. I have browsed many sites to look for examples of how to
store the entry data, so that the user can go back and forward along
the sign -up process. I am currently trying to use a Session object to
store all these details and get them back out of session as each step
is selected.

My model was a HashTable of NameValueCollection, so I could go to the
hash for the particular step, and get the name key value pairs of each
data.

My problem is when I go to recollect the session object (Effectively a
hash table). The object has no data, ie Hash count items = 0. however
when I store this hash table to the Session object it has 5 or 6 items
..

There is something obviously happening when the object is being stored,
maybe a serialization issue.. I am new to this development so would
appreciate any pointers that people may have, or another technique I
can use? Perhaps NameValueCollection or HashTable cant be stored in
session? but why then are they serilaizable?

Many thanks

Richard

Feb 17 '06 #4
Hi Nicholas as an aside, I seem to have a valid hashtable stored in the
session under that variable as the speciric cast to my Wizard session
object is working with no exceptions thrown: below is my class just in
case I cam doing something completely incorrect (which is alway
possible :))
/// <summary>
/// Summary description for AddStockSession.
/// </summary>
public class WizardSession : Hashtable {
public WizardSession():base() {

}

/// <summary>
/// Add an object to the current context
/// </summary>
/// <param name="context">The context to add this key/pair to. Is the
hashcode of the </param>
/// <param name="key">The key to get this variable</param>
/// <param name="value">The value of the variable</param>
public void Add(string context, string name, string value) {
NameValueCollection collection ;

//retrieve the collection at this context
if (this[context] == null) {
//create it is it does no exist
collection = new NameValueCollection();
base.Add(context, new NameValueCollection());
}

//get the collection
collection = (NameValueCollection)this[context];

if (collection[name] != null) {
//if it exists remove
collection.Remove(name);
}

collection.Add(name, value);

//reassign (I think needed as references are used);
base[context] = collection;
}
/// <summary>
/// Returns the value of the variable on the page
/// </summary>
/// <param name="context">The context to get, is the hashcode</param>
/// <param name="key">The variable that is needed</param>
/// <returns>The variable as a string. String.Empty if fail</returns>
public string Get(string context, string key) {
if (this[context] != null) {
NameValueCollection collection =
(NameValueCollection)this[context];

if (collection[key] != null) {
return collection[key].ToString();
}
}

return String.Empty;
}
}

Feb 17 '06 #5
Hi Nicholas,

Having spent a fantastic amount of time on this, it finally became a
gotcha... The session was being re-initilised on a ispostback call on a
page load!! I need to look into why when I click on my "Next" button is
defines ispostback as false, but hey thats another issue.

For now I would like to thankyou for being my "cardboard janitor", I
dont normally post on gotchas like this but was struggling today.. But
at least I know that storing these things in sessions is probebly the
right way to go.... in fact I am developing this class so that it loops
on all controls within a Panel within a user control to make it
automatic when you add the control to any page, (using wither the
hashcode for the control or the user defined ID)... not sure why .NET
1.1 doesn;t have this kind of facility anyway... Perhaps time for .NET
2.0 which I see has this as standard :)

Many thanks

Richard

Feb 17 '06 #6
Hi Nicholas as an aside, I seem to have a valid hashtable stored in the
session under that variable as the speciric cast to my Wizard session
object is working with no exceptions thrown: below is my class just in
case I cam doing something completely incorrect (which is alway
possible :))
/// <summary>
/// Summary description for AddStockSession.
/// </summary>
public class WizardSession : Hashtable {
public WizardSession():base() {

}

/// <summary>
/// Add an object to the current context
/// </summary>
/// <param name="context">The context to add this key/pair to. Is the
hashcode of the </param>
/// <param name="key">The key to get this variable</param>
/// <param name="value">The value of the variable</param>
public void Add(string context, string name, string value) {
NameValueCollection collection ;

//retrieve the collection at this context
if (this[context] == null) {
//create it is it does no exist
collection = new NameValueCollection();
base.Add(context, new NameValueCollection());
}

//get the collection
collection = (NameValueCollection)this[context];

if (collection[name] != null) {
//if it exists remove
collection.Remove(name);
}

collection.Add(name, value);

//reassign (I think needed as references are used);
base[context] = collection;
}
/// <summary>
/// Returns the value of the variable on the page
/// </summary>
/// <param name="context">The context to get, is the hashcode</param>
/// <param name="key">The variable that is needed</param>
/// <returns>The variable as a string. String.Empty if fail</returns>
public string Get(string context, string key) {
if (this[context] != null) {
NameValueCollection collection =
(NameValueCollection)this[context];

if (collection[key] != null) {
return collection[key].ToString();
}
}

return String.Empty;
}
}

Feb 17 '06 #7
Richard,
Maybe its late and I'm not thinking, but I don't see anywhere in your code
where you are adding any name/value pairs to your NameValueCollection before
using it as the second parameter to the Hashtable's Add method.

What I'd do is simplify this:
1) use a regular Hashtable
2) have a small class with an Name and a Value field.
3) in your add method, create an instance of this class and populate the
fields,
4) Then add this to the Hashtable using context as the key, and your class
as the value.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"rg*******@hotmail.com" wrote:
Hi Nicholas as an aside, I seem to have a valid hashtable stored in the
session under that variable as the speciric cast to my Wizard session
object is working with no exceptions thrown: below is my class just in
case I cam doing something completely incorrect (which is alway
possible :))
/// <summary>
/// Summary description for AddStockSession.
/// </summary>
public class WizardSession : Hashtable {
public WizardSession():base() {

}

/// <summary>
/// Add an object to the current context
/// </summary>
/// <param name="context">The context to add this key/pair to. Is the
hashcode of the </param>
/// <param name="key">The key to get this variable</param>
/// <param name="value">The value of the variable</param>
public void Add(string context, string name, string value) {
NameValueCollection collection ;

//retrieve the collection at this context
if (this[context] == null) {
//create it is it does no exist
collection = new NameValueCollection();
base.Add(context, new NameValueCollection());
}

//get the collection
collection = (NameValueCollection)this[context];

if (collection[name] != null) {
//if it exists remove
collection.Remove(name);
}

collection.Add(name, value);

//reassign (I think needed as references are used);
base[context] = collection;
}
/// <summary>
/// Returns the value of the variable on the page
/// </summary>
/// <param name="context">The context to get, is the hashcode</param>
/// <param name="key">The variable that is needed</param>
/// <returns>The variable as a string. String.Empty if fail</returns>
public string Get(string context, string key) {
if (this[context] != null) {
NameValueCollection collection =
(NameValueCollection)this[context];

if (collection[key] != null) {
return collection[key].ToString();
}
}

return String.Empty;
}
}

Feb 17 '06 #8
HI Nicholas/Peter

Many thanks for your replies... I finally found out the issue, and
unfortunately it was a gotcha... My Page_Load even was re-initilaising
my Search, therefore no items:( Very embarrassed, I do not usually
post these things but have spent a LONG time on this today and wanted
to throw it out there in case there was some kind of serialization
issue, which as you may have guessed I was focusing on... I guess I
have learnt that this seems the correct way to do the storing of data
on a wizard process, so thankyou for that.

I am surprised that someone hasn;t developed a framework for this, I am
looking to develop this for all our client sites so making the class
generic, using control ids etc for referencing in the wizard object. (I
do this with PHP all the time and its very successful).

I guess .NET 2.0 is the way to go as I see this has this as standard, I
am also finding that paging data in .NET 1.1 with SQL Server 2000 is a
"grey" area as well, so maybe time to upgrade to Server 2005/.NET 2.0

Anyway many thanks for your replies, its nice to know that there is
someone to help and vica versa.

Richard

Feb 17 '06 #9

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

Similar topics

3
by: Tony | last post by:
Hello. What is hash table? i could only find small reffrence to hash table .. but what exactly is this and how can i creat them? Is there any website with tutorial on this subject ? Thanks
4
by: Pelo GANDO | last post by:
Hi everybody ! I am a beginner in C++. I am looking for a (simple if it's possible) source code in C++ about hash table... Thank you ! Pelo
2
by: Ravi | last post by:
Hi, I am working on a winform app. I need to use an object which can store some information(key/value pairs) and also can be acessed by multiple threads(read/write). From what I heard Hash table...
7
by: Diane | last post by:
Hi everybody. Does anyone have any sample hash table implementation for separate chaining? I'm trying to implement it myself, but I'm stuck. Thanks!
24
by: kdotsky | last post by:
Hello, I am using some very large dictionaries with keys that are long strings (urls). For a large dictionary these keys start to take up a significant amount of memory. I do not need access to...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
9
by: david | last post by:
I have a class with some business-logic and with every roundtrip, I need an instance of this class, so I have to create it, every time again. That doesn't seem very efficient. I thought it would...
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.