I am having a hard time adding a 2nd field to my cookie for some odd reason I can't seem to figure it out. What I am trying to do is have a page that you enter a First name and Last name into it, and then when you click continue it stores those 2 into a cookie, then it redirects to Order page that says "Welcome back Mercenary". Now on order page I have a button that goes back to original page with the 2 name text boxes. I wish for those to be populated with the previous data, and if I change it to have it update the 2nd page with the changes. Any help would be appreciated. Here is my code
protected void btnContinue_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
DateTime expiry = DateTime.Now.AddMinutes(5);
this.SetResponseCookie("FirstName", txtFirstName.Text, expiry);
this.SetResponseCookie("LastName", txtLastName.Text, expiry);
}
Response.Redirect("~/Order.aspx");
}
private void SetResponseCookie(string name, string value,
DateTime expiry)
{
HttpCookie cookie = new HttpCookie("FirstName", txtFirstName.Text);
cookie.Values.Add("LastName", txtLastName.Text);
cookie.Expires = expiry;
Response.Cookies.Add(cookie);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
if (!(Request.Cookies["FirstName"] == null))
txtFirstName.Text = Request.Cookies["FirstName"].Value;
if (!IsPostBack)
if (!(Request.Cookies["LastName"] == null))
txtLastName.Text = Request.Cookies["LastName"].Value;
}
Right now, once I hit continue it goes to the Order page with "Welcome back Mercenary&LastName=One!" and if I tell it to go back to the first page it fills it with "Mercenary&LastName=One"
Any help would be appreciated.
No comments:
Post a Comment