Wednesday, February 25, 2009

Save and retrieve information from the session (by default expires in 20)

Saving in the session

protected void LoginButton_Click(object sender, EventArgs e)
{
string username = NameTextBox.Text;

//HttpCookie cookie = new HttpCookie("UserInfo");
//cookie["Username"] = username;
//cookie.Expires = DateTime.Now.AddDays(1);
//Response.Cookies.Add(cookie);

Session["Username"] = username;
Response.Redirect("OrderPage.aspx");
}


Retrieving

protected void ProceedButton_Click(object sender, EventArgs e)
{
string username = (string)Session["Username"];
string product = ProductTextBox.Text;
Session["Product"] = product;

string url = string.Format("CustomerDetails.aspx");
Response.Redirect(url);
}

No comments:

Post a Comment