【发布时间】:2014-09-15 08:55:37
【问题描述】:
试图在这个程序上工作,理论上它应该将名字和姓氏都检索到“欢迎”lblMessage。在 ASP.NET 中使用 Cookie。
它IS所做的只是检索 ["FirstName"]。我需要两者。
Order.aspx.cs
protected void Page_Load(object sender, EventArgs e){
string firstName = (string)Session["FirstName"];
string lastName = (string)Session["LastName"];
if ((firstName != null) && (lastName != null))
{
lblWelcome.Text = "Welcome back, " + (string)Session["FirstName"] + (string)Session[" LastName"] + "!";
}
}
CheckOut.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
// get entry data from cookies
//if (Request.Cookies["FirstName"] != null)
// txtFirstName.Text = Request.Cookies["FirstName"].Value;
//if (Request.Cookies["LastName"] != null)
// txtLastName.Text = Request.Cookies["LastName"].Value;
//get entry data from session state
if (!IsPostBack)
{
string firstName = (string)Session["FirstName"];
if (firstName != null) txtFirstName.Text = (string)Session["FirstName"];
string lastName = (string)Session["LastName"];
if (lastName != null) txtLastName.Text = (string)Session["LastName"];
txtFirstName.Focus();
}
}
private void LoadCustomerData()
{
Session["FirstName"] = txtFirstName.Text;
Session["LastName"] = txtLastName.Text;
}
在几个部分 [w/o 显示整个代码] 这是我迄今为止所拥有的。
想知道是否有人可以用一双新的眼光来看看我做错了什么?
【问题讨论】:
标签: c# asp.net session cookies