Nodes.Clear() is also erasing my session variables

A

Alex D.

Hi. I have a TreeView stored in a session variable...is ok...problem is when
I use Nodes.Clear() then my session variable that holds the TreeView is also
emptied! Is this behavior by design or it's some kind of bug??

Thanks,

Alex.
 
R

Robbe Morris [C# MVP]

See post from above. There is no logical reason
to store the control itself in session.
 
B

Bruce Barker

yes, by design.

if you use inproc sessions (the default), you a storing a reference to
control in session. if you make changes to the control, the changes are
reflected in session because its the same object. this is different than
value types.


string a = "hello";
string b = a; // b = "hello";
a = "bye"; // b still = "hello" because a now points to a new string

now lets look at objects

class test {
public string value = "hello";
}

test a = new test();
test b = a;
a.value = "bye"; // b.value = "bye", because a is not pointing to
a new object,
// a method was just called on the
common object
a = new test(); // make a point to new object
a.value = "more"; // b.value is still "bye", because a now points to
a new object


-- bruce (sqlwork.com)
 
A

Alejandro Penate-Diaz

yes...I dont know why I thougt that session variables were only values and
no references....thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top