我想创建一个对象,然后将它保存在一个Session中,然后重定向到另一个页面并使用会话中保存的对象。在会话中保存一个已经创建的对象
这是我的代码,这似乎是错误的地方,因为它不可操作。
PAGE 1
public FitnessClassOpportunity GetData()
{
return new FitnessClassOpportunity(txtId.Text, txtDescription.Text, txtLocation.Text,
Convert.ToInt32(tx2.Text), dropDownDay.SelectedItem.ToString(),
txtTime.Text, Convert.ToInt32(txtDuration.Text), CheckBox1.Checked,
txtDatecompleted.Text, txtNumSession.Text);
}
protected void Button1_Click(object sender, EventArgs e)
{
//result from breaking point: f has the data
FitnessClassOpportunity f = GetData();
//result from breaking point: f still has the data but Session is still NULL
Session["object"] = f;
Response.Redirect("Default.aspx");
}
PAGE 2
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
}
else
{
//add the object from the session to a list
fitnessClassList.addFitnessClass((FitnessClassOpportunity)Session["object"]);
UpdateListbox();
}
}
什么是'fitnessClassList'和'addFitnessClass'是什么?你有任何错误? – 2012-03-27 20:42:23
你确定重定向被认为是回发吗?我的猜测是,代码根本不会被执行。 – 2012-03-27 20:43:35
我想你应该将addFitnessClass&UpdateListbox代码移动到if的_then_分支。 – 2012-03-27 20:44:41