Can someone please assist me? I am trying to pass information from page 1 to page 2 using cookies. However, every time I click the "add" button, a new cookie is set instead of modifying the value and keeping the same name. How can I read all cookies as a list?
Here is my code:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie Cookie = new HttpCookie("result");
Cookie["text1"] = TextBox1.Text;
Cookie["text2"] = TextBox2.Text;
Cookie.Expires = DateTime.Now.AddDays(2);
Response.Cookies.Add(Cookie);
Response.Redirect("WebForm2.aspx");
}
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie Cookie = Request.Cookies["result"];
if (Cookie != null)
{
Ldonate.Text = Cookie["text1"] ;
Litem.Text = Cookie["text2"] ;
}