Cookies:
Cookies are a small amount of memory used by web server within Client system. The purpose is maintaining personal info of client within Client system to reduce burden on server.
Ex: Personal information can be login parsers, Session ID, Security tokens, Questions answered by user etc...
Lets we see how cookies are working...
The below code explains a clear view about cookies.
In that one i use two label box and 2 textbox and one button control.
Whenever the user type their name and age into the textbox and Click the button means that information has to be stored in cookies(Temporary Storage).
If we click the "DisplayCookie button means the stored information in the cookie will be retrieved and load into the GridView..
Try the Sample demo...
The below code explains a clear view about cookies.
In that one i use two label box and 2 textbox and one button control.
Whenever the user type their name and age into the textbox and Click the button means that information has to be stored in cookies(Temporary Storage).
If we click the "DisplayCookie button means the stored information in the cookie will be retrieved and load into the GridView..
Try the Sample demo...
Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie aCookie = new HttpCookie("userInfo");
aCookie.Values["uname="] = TextBox1.Text;
aCookie.Values["age="] = TextBox2.Text.ToString();
aCookie.Values["lastVisit="] = DateTime.Now.ToString();
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);
}
protected void Button2_Click(object sender, EventArgs e)
{
ArrayList colCookies = new ArrayList();
for (int i = 0; i < Request.Cookies.Count; i++)
colCookies.Add(Request.Cookies[i]);
GridView1.DataSource = colCookies;
GridView1.DataBind();
}
}