473,408 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

session variables

hi all,

I have a problem. I have a class file name Agent which has Name and
SalesPerson as two strings. On below page, am reading session object called
agentdetail of class Agent and filling out agency name and salesperson name
on page load event

public partial class AgentDetail : System.Web.UI.Page

{

Agent agentdetail = new Agent();

protected void Page_Load(object sender, EventArgs e)

{ if (Session["agentdetail"] != null)

{ agentdetail = (Agent)Session["agentdetail"];

agencyname.Text = agentdetail.Name;

asalesperson.Text = agentdetail.SalesPerson;

}}

}

Now on button called proceed, am saving agency name and sales person name
again in agentdetail object and adding it into session variable called
"agentdetail". Now if I come back to this page and change agencyname or
sales person name then its not saving changes to the new object in the
session. Eg - if I have "abc" as agency name and "myagent" as agent name
which on proceed button, I save it in session varialbe called agentdetail.
Now when I come back to page, it shows correct details and if I change sales
person name to "youragent" and them comee back to this page, it still shows
"myagent" .....

protected void proceed_Click(object sender, EventArgs e)

{ agentdetail.Name = agencyname.Text;

agentdetail.SalesPerson = asalesperson.Text;

Session.Add("agentdetail", agentdetail); // in short here it is
not replacing the agentdetail variable which is alredy stored in session.

}

I don't know where am going wrong. Pls help...........(am kinda new to c#)

here is the structure of Address class file

public class Agent

{

private string name;

private string salesPerson;

public string Name

{

get { return this.name; }

set { this.name = value; }

}
public string SalesPerson

{

get { return this.salesPerson; }

set { this.salesPerson = value; }

}

}


May 18 '06 #1
2 1872
The problem is not with storing the value in the session variable. That
part of the code is working fine.

The problem is that the Page_Load method is called before the
proceed_Click method, so you will be getting the old values from the
session variable and putting them in the text boxes. the procees_Click
method then takes those values and successfully put them back in the
session variable.

Make the code in the Page_Load method check the value of Page.IsPostback
to determine if the text boxes should be populated or not.
puja wrote:
hi all,

I have a problem. I have a class file name Agent which has Name and
SalesPerson as two strings. On below page, am reading session object called
agentdetail of class Agent and filling out agency name and salesperson name
on page load event

public partial class AgentDetail : System.Web.UI.Page

{

Agent agentdetail = new Agent();

protected void Page_Load(object sender, EventArgs e)

{ if (Session["agentdetail"] != null)

{ agentdetail = (Agent)Session["agentdetail"];

agencyname.Text = agentdetail.Name;

asalesperson.Text = agentdetail.SalesPerson;

}}

}

Now on button called proceed, am saving agency name and sales person name
again in agentdetail object and adding it into session variable called
"agentdetail". Now if I come back to this page and change agencyname or
sales person name then its not saving changes to the new object in the
session. Eg - if I have "abc" as agency name and "myagent" as agent name
which on proceed button, I save it in session varialbe called agentdetail.
Now when I come back to page, it shows correct details and if I change sales
person name to "youragent" and them comee back to this page, it still shows
"myagent" .....

protected void proceed_Click(object sender, EventArgs e)

{ agentdetail.Name = agencyname.Text;

agentdetail.SalesPerson = asalesperson.Text;

Session.Add("agentdetail", agentdetail); // in short here it is
not replacing the agentdetail variable which is alredy stored in session.

}

I don't know where am going wrong. Pls help...........(am kinda new to c#)

here is the structure of Address class file

public class Agent

{

private string name;

private string salesPerson;

public string Name

{

get { return this.name; }

set { this.name = value; }

}
public string SalesPerson

{

get { return this.salesPerson; }

set { this.salesPerson = value; }

}

}

May 18 '06 #2

I have a "smarter" web session object holder at:
http://spaces.msn.com/sholliday/ 10/24/2005 entry

and an example .... doing pretty much what you're doing.
"puja" <pu********@leap.com.au> wrote in message
news:eD**************@TK2MSFTNGP03.phx.gbl...
hi all,

I have a problem. I have a class file name Agent which has Name and
SalesPerson as two strings. On below page, am reading session object called agentdetail of class Agent and filling out agency name and salesperson name on page load event

public partial class AgentDetail : System.Web.UI.Page

{

Agent agentdetail = new Agent();

protected void Page_Load(object sender, EventArgs e)

{ if (Session["agentdetail"] != null)

{ agentdetail = (Agent)Session["agentdetail"];

agencyname.Text = agentdetail.Name;

asalesperson.Text = agentdetail.SalesPerson;

}}

}

Now on button called proceed, am saving agency name and sales person name
again in agentdetail object and adding it into session variable called
"agentdetail". Now if I come back to this page and change agencyname or
sales person name then its not saving changes to the new object in the
session. Eg - if I have "abc" as agency name and "myagent" as agent name
which on proceed button, I save it in session varialbe called agentdetail.
Now when I come back to page, it shows correct details and if I change sales person name to "youragent" and them comee back to this page, it still shows "myagent" .....

protected void proceed_Click(object sender, EventArgs e)

{ agentdetail.Name = agencyname.Text;

agentdetail.SalesPerson = asalesperson.Text;

Session.Add("agentdetail", agentdetail); // in short here it is not replacing the agentdetail variable which is alredy stored in session.

}

I don't know where am going wrong. Pls help...........(am kinda new to c#)

here is the structure of Address class file

public class Agent

{

private string name;

private string salesPerson;

public string Name

{

get { return this.name; }

set { this.name = value; }

}
public string SalesPerson

{

get { return this.salesPerson; }

set { this.salesPerson = value; }

}

}

May 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an...
6
by: Lina Manjarres | last post by:
Hello, I have a session variable in a login page. Then I go to a form page where I uses the ProfileID and the UserID. Then I go to a result page where I would like to use the UserID as a filter,...
4
by: PJ | last post by:
A particular page seems to be having issues with correctly setting Session variables. I am setting a couple of session variables on the Page_Unload event. While stepping through code, the...
31
by: Harry Simpson | last post by:
I've come from the old ASP camp where session variables were not used. When i started using ASP.NET in 2001, I started using them again because it was ok from what I'd read. I've been merrily...
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
3
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
3
by: Phillip N Rounds | last post by:
I'm writing a user control which has two states: Active & InActive. I additionally am required that there to be only one active control per page, and all logic has to be contained within the...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
26
by: BillE | last post by:
Some ASP.NET applications use Session Variables extensively to maintain state. These should be re-written to use viewstate, hidden fields, querystring, etc. instead. This is because if a user...
12
by: MrHelpMe | last post by:
Hello again all, I've finished my whole application and now I don't like the whole session variables that I am using. I have a form, user fills in info clicks submit and using CDOSYSMail an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.