User-1473429353 posted
Hi,
I'm making a car purchasing website just for practice and have to make an add to cart feature using cookies. I want to set the car id as the cookie in the add to cart button but then in the cart.aspx.cs I want to use this id cookie to get the details related
to the car from the database (image, make, model, colour and price).
I have this code on my product page for the add to stock button which my manager helped me with:
protected void AddToCartBtn_Click(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("ShoppingCart");
cookie["ID"] = Newtonsoft.Json.JsonConvert.SerializeObject(cookie);
cookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(cookie);
Response.Redirect("Cart.aspx");
}
I am not sure if this is right and I also don't know what to add to the cart.aspx.cs to get the data from the database using the cookie and save them in my labels. If someone could make this a bit clearer for me to understand that would be great.