Re: Session variables and reference
- From: "Cowboy \(Gregory A. Beamer\)" <NoSpamMgbworld@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 19 Jul 2007 10:40:13 -0500
If you are going the session route, I find it easier to store ina data
format, like a DataSet. This is not applicable for all.
If you are using a single page for the info, consider ViewState instead. You
are still better to control your own destiny, of course.
I have never had problems with objects in Session, but I am not extensive in
my use of Session either, as I can normally find a better way for my
applications.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)
************************************************
Think outside the box!
************************************************
"Vince13 via DotNetMonster.com" <u35350@uwe> wrote in message
news:75692e15875a8@xxxxxx
I am trying to set up a page where the user can change data, and then click
cancel and the data will not be saved. Currently, I am saving the data in
a
Session variable that is an array of a class I created:
public class cut
{
public cut()
{
ParallelDim = 'G';
cutPoint = ++numCuts;
Knom = 0;
Kmin = 0;
Kmax = 0;
//numCuts++;
}
public cut(cut myCut) //copy constructor
//**note, does NOT increment numCuts
{
ParallelDim = myCut.ParallelDim;
cutPoint = myCut.cutPoint;
Knom = myCut.Knom;
Kmin = myCut.Kmin;
Kmax = myCut.Kmax;
}
public char ParallelDim;
public int cutPoint;
public decimal Knom;
public decimal Kmin;
public decimal Kmax;
public static int numCuts = 0;
}
I realized that when I set my temporary array to equal the session array,
it
was passing the values by reference, so I created new objects using a copy
constructor:
for(int i = 0; i < 20; ++i) //uses copy constructor to initiate myCuts and
make copy so the
{ //changes are not made to Session[allcuts]
myCuts[i] = new cut(((cut[])Session["allCuts"])[i]);
//uses copy constructor to make
identical array
}
This works in that it does create a new array that is not just a reference
to
the old one, but for some reason I cannot write the data back to the
session
array. I am fairly sure it should just work like this:
Session["allCuts"] = myCuts;
but I have also tried using the copy constructor again (reverse of above)
and
setting each individual value of the class separately. Nothing will write
the data back to the session array.
If ANYONE has any ideas, I would greatly appriciate it.
--
Message posted via http://www.dotnetmonster.com
.
- References:
- Session variables and reference
- From: Vince13 via DotNetMonster.com
- Session variables and reference
- Prev by Date: Re: Membership database problems
- Next by Date: RE: Session variables and reference
- Previous by thread: Session variables and reference
- Next by thread: RE: Session variables and reference
- Index(es):
Relevant Pages
|