日期:2014-05-17 浏览次数:20636 次
public partial class broswer : System.Web.UI.Page
{
protected void Button1_Click1(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("things");
cookie.Expires = DateTime.Now.AddMinutes(10.0);
int i = 1;
CheckBox box = new CheckBox();
for (i = 0; i < 6; i++)
{
int temp = i;
box = (CheckBox)Form.FindControl("CheckBox" + (temp + 1).ToString());
if (box != null && box.Checked == true)
{
cookie.Values["ID"+temp.ToString()] = box.ID;
cookie.Values["name"+temp.ToString()] = box.Text;
Response.Cookies.Add(cookie);
}
}
Response.Write("<script>alert('已将所选加入购物车')</script>");
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("index.aspx");
}
}
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int i=1;
HttpCookie getCookie = Response.Cookies["things"];
while(getCookie.Values["name"+i.ToString()]!=null)
{
Label1.Text = getCookie.Values["name" + i.ToString()].ToString();
Label2.Text = getCookie.Values["ID" + i.ToString()].ToString();
i++;
}
}
}
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int i=1;
HttpCookie getCookie = Response.Cookies["things"];//Request.Cookies["things"];
while(getCookie.Values["name"+i.ToString()]!=null)
{
Label1.Text = getCookie.Values["name" + i.ToString()].ToString();
Label2.Text = getCookie.Values["ID" + i.ToString()].ToString();
i++;
}
}
}
------解决方案--------------------
楼上正解。
获取cookie用Request