By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,209 Members | 1,706 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,209 IT Pros & Developers. It's quick & easy.

Storing Controls as session variables?

P: n/a
is it possible? pros and cons?
Nov 23 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Don't forget that, if your clients browser disables cookies in his computer,
session will not be used by him.

"Alex D." <al********@hotmail.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
is it possible? pros and cons?

Nov 23 '05 #2

P: n/a
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hotmail.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
is it possible? pros and cons?

Nov 23 '05 #3

P: n/a
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hotmail.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
is it possible? pros and cons?


Nov 23 '05 #4

P: n/a
The answer is both yes, and no. Yes you can store any object you want in
sessions, including control instances. But, upon return trips, the instance
you have in session will no longer map to the instance built when ASP.NET
constructs the object model, therefore, any changes made to the object in
session will not be reflected in the page output. The object model is
rebulit on each request.

"Alex D." <al********@hotmail.com> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hotmail.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
is it possible? pros and cons?



Nov 23 '05 #5

P: n/a
but instead...the other way around any changes in the original control will
be reflected in the session object?? uhmmm
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The answer is both yes, and no. Yes you can store any object you want in
sessions, including control instances. But, upon return trips, the
instance you have in session will no longer map to the instance built when
ASP.NET constructs the object model, therefore, any changes made to the
object in session will not be reflected in the page output. The object
model is rebulit on each request.

"Alex D." <al********@hotmail.com> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hotmail.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
is it possible? pros and cons?



Nov 23 '05 #6

P: n/a
Obviously not if they do not reference the same object.

It might be something like the following example:

string strA = "hello world!";
string strB = strA;

//
// The two variables refer to the same object just as if you put a control
in the session.
//

strB = null;
strB = "hello world!";

//
// Just as with a page request, strB above is reset and although contains
the same content, they
// are two different objets in memory.
//

I would imaging the same thing happens with the object model. Changes made
in either are not seen by the other.
"Alex D." <al********@hotmail.com> wrote in message
news:OJ*************@TK2MSFTNGP10.phx.gbl...
but instead...the other way around any changes in the original control
will be reflected in the session object?? uhmmm
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The answer is both yes, and no. Yes you can store any object you want in
sessions, including control instances. But, upon return trips, the
instance you have in session will no longer map to the instance built
when ASP.NET constructs the object model, therefore, any changes made to
the object in session will not be reflected in the page output. The
object model is rebulit on each request.

"Alex D." <al********@hotmail.com> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hotmail.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
> is it possible? pros and cons?
>



Nov 23 '05 #7

P: n/a
No. Why would you want to store the entire control
in session? I can think of several negatives. What
would be the positive?

That said...

You'd have to research whether the controls
you are saving to session are serializable. If not,
you could never deploy your site in a web farm or
use anything but InProc on a single server.

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hotmail.com> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hotmail.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
is it possible? pros and cons?



Nov 23 '05 #8

P: n/a
may be your example using strings is not the most appropriate in this case
because strings I think are considered a basic type so it is a value type
and not a reference.
and what it seems to me is that reference types are stored as references in
session variables, but instead of that what I needed was to save it as a
value type so I would be a different object.

"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:Oz**************@tk2msftngp13.phx.gbl...
Obviously not if they do not reference the same object.

It might be something like the following example:

string strA = "hello world!";
string strB = strA;

//
// The two variables refer to the same object just as if you put a control
in the session.
//

strB = null;
strB = "hello world!";

//
// Just as with a page request, strB above is reset and although contains
the same content, they
// are two different objets in memory.
//

I would imaging the same thing happens with the object model. Changes
made in either are not seen by the other.
"Alex D." <al********@hotmail.com> wrote in message
news:OJ*************@TK2MSFTNGP10.phx.gbl...
but instead...the other way around any changes in the original control
will be reflected in the session object?? uhmmm
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The answer is both yes, and no. Yes you can store any object you want
in sessions, including control instances. But, upon return trips, the
instance you have in session will no longer map to the instance built
when ASP.NET constructs the object model, therefore, any changes made to
the object in session will not be reflected in the page output. The
object model is rebulit on each request.

"Alex D." <al********@hotmail.com> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
> Why would you ever want to do this? I could see
> storing the data used to populate the control
> by why the entire control itself? Tons more
> overhead with no additional benefit...
>
> --
> Robbe Morris - 2004/2005 Microsoft MVP C#
> http://www.masterado.net
>
>
>
>
>
> "Alex D." <al********@hotmail.com> wrote in message
> news:uy**************@TK2MSFTNGP14.phx.gbl...
>> is it possible? pros and cons?
>>
>
>



Nov 23 '05 #9

P: n/a
a simple use for a TreeView in a session variable is to keep the
collapsed/expanded info for every node when in the postback you redraw the
entire tree and loose all the properties...then you can restore this values
very easily in each postback. so your tree "remember" which nodes where
collapsed and which expanded...
of course there are many ways of doing this...actually I already used a
different approach...but in the session variable didnt work because just
after repopulating the tree also the session stored tree was affected and
all info erased.

"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
No. Why would you want to store the entire control
in session? I can think of several negatives. What
would be the positive?

That said...

You'd have to research whether the controls
you are saving to session are serializable. If not,
you could never deploy your site in a web farm or
use anything but InProc on a single server.

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hotmail.com> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hotmail.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
is it possible? pros and cons?



Nov 23 '05 #10

P: n/a
Hi, how did you implement the "remembering" of which nodes where
collapsed or expanded?? I'd love to know how you did this.

Thanks!
Henry

Dec 7 '05 #11

P: n/a
I didn't know as well.
I currently enum allnodes in a string(builder) "01011" etc.
Which i hold in the session
On page load i set these again.
<he***********@gmail.com> schreef in bericht
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi, how did you implement the "remembering" of which nodes where
collapsed or expanded?? I'd love to know how you did this.

Thanks!
Henry

Dec 7 '05 #12

P: n/a
AJ
Good answer

"Edwin Knoppert" <ne**@hellobasic.com> wrote in message
news:43**********************@text.nova.planet.nl. ..
I didn't know as well.
I currently enum allnodes in a string(builder) "01011" etc.
Which i hold in the session
On page load i set these again.
<he***********@gmail.com> schreef in bericht
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi, how did you implement the "remembering" of which nodes where
collapsed or expanded?? I'd love to know how you did this.

Thanks!
Henry


Dec 7 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.