Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session in C# not holding value after post back

Status
Not open for further replies.

need2progm

Programmer
Dec 13, 2002
92
US
I do this all day long at my job in vb.net.. very new to c#.

I set my session in If not post back....
Session["newCollection"] = newCollection;


Then try to refer to that session in a method...
SongCollection newCollection = new SongCollection();
Session.Contents["newCollection"] = newCollection;

//add to collection
newCollection.Add(aBrandNewSong);
//so I can do this
foreach (Song aSong in newCollection)
//add to grid
//the newly added object diaplay's the others are gone ?

My thought was syntax ...cuz I am so new to the c way of doing things

Carly
 
Session.Contents["newCollection"] = newCollection;

is backwards if you're trying to assign the session object to your local object. Should be:

newCollection = Session.Contents["newCollection"];

right to left assignment (same as vb)
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
I wasn't refering to the collection corectly .. right to left .. left to right... d--- one of these days I will learn.

This is what I did...

//set session
Session["newCollection"] = newCollection;
//refer to it in a click_event
SongCollection newCollection = (SongCollection)Session["newCollection"];
//add to collection
newCollection.Add(aBrandNewSong);
//loop and display in grid
foreach (Song aSong in newCollection)

Works great



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top