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

session variables

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.