Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, i was assigned from work to create a wishlist in c# using cookies but i cant figure out what to do.
I need a user pressing a button (Heart Shape) to add a product in his wish list.
Can anyone help me.
Keep in mind i am new to C# in asp.net.

What I have tried:

This is my code until now

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_WishListAdd : System.Web.UI.Page
{
    //DataClassesDataContext db = new DataClassesDataContext();

    Product prod = new Product();

    string p_id, p_btitle, p_img, p_desel, p_desen;

    protected void WishAdd(object sender, EventArgs e)
    {

   
        p_id = prod.ProductID.ToString();
        p_btitle = prod.ModelNameEl;
        p_img = prod.ProductImage;
        p_desel = prod.DescriptionEl;
        p_desen = prod.DescriptionEn;

        HttpCookie WishCookies = new HttpCookie("WishCookies");
        WishCookies.Value = prod.ProductID.ToString();
        WishCookies.Expires = DateTime.Now.AddHours(2);
        Response.Cookies.Add(WishCookies);


    }

}
Posted
Updated 11-Feb-19 5:06am

1 solution

It's quite simple. For
A) single value, use HttpCookie.Value Property (System.Web) | Microsoft Docs[^]
B) multiple values, use: HttpCookie.Values Property (System.Web) | Microsoft Docs[^]

HttpCookie WishCookie = new HttpCookie("WishList");
//A)
WishCookie.Value = "Whatever";
//B)
//WishCookie.Values["Val1"] = "1";
//WishCookie.Values["Val2"] = "2";
//WishCookie.Values["Val3"] = "3";
WishCookies.Expires = DateTime.Now.AddHours(2);
Response.Cookies.Add(WishCookie);


Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900