using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Ex6_8 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["mycookie"]!=null)
        {
            txtname.Text = Request.Cookies["mycookie"].Value;
        }
    }
    protected void btnsave_Click(object sender, EventArgs e)
    {
        Response.Cookies["mycookie"].Value = txtname.Text;
        Response.Cookies["mycookie"].Expires = DateTime.Now.AddDays(30);
    }
    protected void btnclear_Click(object sender, EventArgs e)
    {
        HttpCookie acookie;
        string ckname;
        int cknum = Request.Cookies.Count;
        for (int i = 0; i < cknum; i++)
        {
            ckname = Request.Cookies[i].Name;
            acookie = new HttpCookie(ckname);
            acookie.Expires = DateTime.Now.AddDays(-1);
            Response.Cookies.Add(acookie);
        }
        Response.AddHeader("Refresh", "0");
    }
}
