Home All Groups Group Topic Archive Search About

One comment about the implementation of Session

Author
22 Nov 2005 5:37 PM
antonyliu2002
I think it is a bad idea to implement session as a bag of string pairs.
That is, it is not a good idea to force both a key and its value to be
of type String.

It has no problem for most web controls.  For example, for TextBox(es),
we can have the following in the session bag:

"txtFirstName": "John"
"txtLastName": "Doe"

But, the current session implementation is not handy when we have to
store ListItem(s) of a multiple ListBox.

For example, if I have on my web this multi-select ListBox (whose ID is
lstbxFood):

Select your favorite food:

   Hamberger
   Pizza
   Icecream
   French Fries
   Yogurt

And suppose, a user selects the first 3 items: Hamberger, Pizza and
Icecream.

Then, we have a little problem storing in the session all 3 selected
items for the key "lstbxFood".

So, it would be nice if the value of a key in the session can be some
kind of container which can hold multiple objects.

What do you think?

Author
22 Nov 2005 5:47 PM
Alvin Bruney - ASP.NET MVP
Session is not implemented this. The value is of type object. The key is
overloaded to either be a string or an index. It's very possible to do what
you ask
Session["Selections"] = new Array("Hamburger","Pizza","IceCream");
....
Array arr = Session["Selections"] as Array;
foreach (string str in arr)
{
    string.ToString() you get the idea
}
--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



<antonyliu2***@yahoo.com> wrote in message
Show quoteHide quote
news:1132681020.142238.108920@f14g2000cwb.googlegroups.com...
> I think it is a bad idea to implement session as a bag of string pairs.
>  That is, it is not a good idea to force both a key and its value to be
> of type String.
>
> It has no problem for most web controls.  For example, for TextBox(es),
> we can have the following in the session bag:
>
> "txtFirstName": "John"
> "txtLastName": "Doe"
>
> But, the current session implementation is not handy when we have to
> store ListItem(s) of a multiple ListBox.
>
> For example, if I have on my web this multi-select ListBox (whose ID is
> lstbxFood):
>
> Select your favorite food:
>
>    Hamberger
>    Pizza
>    Icecream
>    French Fries
>    Yogurt
>
> And suppose, a user selects the first 3 items: Hamberger, Pizza and
> Icecream.
>
> Then, we have a little problem storing in the session all 3 selected
> items for the key "lstbxFood".
>
> So, it would be nice if the value of a key in the session can be some
> kind of container which can hold multiple objects.
>
> What do you think?
>
Author
22 Nov 2005 6:06 PM
antonyliu2002
Hey, that's what I want, then.  Forget about my stupid comment. Thanks
a lot!
Author
22 Nov 2005 5:58 PM
Patrice
This is actually already what your suggested (the value is an object, not a
string).

--
Patrice

<antonyliu2***@yahoo.com> a écrit dans le message de
Show quoteHide quote
news:1132681020.142238.108920@f14g2000cwb.googlegroups.com...
> I think it is a bad idea to implement session as a bag of string pairs.
>  That is, it is not a good idea to force both a key and its value to be
> of type String.
>
> It has no problem for most web controls.  For example, for TextBox(es),
> we can have the following in the session bag:
>
> "txtFirstName": "John"
> "txtLastName": "Doe"
>
> But, the current session implementation is not handy when we have to
> store ListItem(s) of a multiple ListBox.
>
> For example, if I have on my web this multi-select ListBox (whose ID is
> lstbxFood):
>
> Select your favorite food:
>
>    Hamberger
>    Pizza
>    Icecream
>    French Fries
>    Yogurt
>
> And suppose, a user selects the first 3 items: Hamberger, Pizza and
> Icecream.
>
> Then, we have a little problem storing in the session all 3 selected
> items for the key "lstbxFood".
>
> So, it would be nice if the value of a key in the session can be some
> kind of container which can hold multiple objects.
>
> What do you think?
>