locked
ASP.Net C#/ Use of Cookie RRS feed

  • Question

  • User1698615254 posted

    I have several pictures. These pictures bind from database with repeater in a page. If click on a picture, id is passing to another page.
    This another page has a texbox. I assign id, and other texbox values in a cookie array.

    Int32 id = Convert.ToInt32(Request.QueryString["id"]);
    if (Request.Cookies["cookie"] != null)
    {
    string Cookie = Request.Cookies["cookie"].Value.Split('=')[1];
    HttpCookie arr= new HttpCookie("Cookie");
    arr.Values["Cookie"] = Cookie + "," + id + "-" + b + "-" + c;

    arr= DateTime.Now.AddDays(1);
    Response.Cookies.Add(arr);
    }
    I call this cookie with repeater in a page. I press these values in a ondatabound with for loop in a list.
    Cookie is coming; Cokkie = 1-1-3,6-2-4,10-7-2... But,I can not properly print it.
    How can i do press properly the 3rd column in a label ?

    Thanks...

    Sunday, March 4, 2018 5:09 PM

All replies

  • User-832373396 posted

    Hi <g class="gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="5" data-gr-id="5">dehset</g>,

    Cookie is coming; Cokkie = 1-1-3,6-2-4,10-7-2... But,I can not properly print it.
    How can i do press properly the 3rd column in a label ?

    Sir, I guess that you want this,

    Please refer to 

      HttpCookie arr = new HttpCookie("Cookie");
                arr.Values["Cookie"] = "1-1-3,6-2-4,10-7-2";
                arr.Expires = DateTime.Now.AddDays(1);
                Response.Cookies.Add(arr);

    Next

    @{ 
        string str = Request.Cookies["Cookie"]["Cookie"];
        foreach (var b in str.Split(',').ToList()) {
            <label>@b</label>
        }

    Then it generates this as shown below at page

    <label>1-1-3</label>
    <label>6-2-4</label>
    <label>10-7-2</label>

    and Way2

      List<string> c = str.Split(',').ToList();    
        for (int i = 0; i < c.Count(); i++)
        {
            if (i == 2)
            {<label>@c[i]</label>}
        }

    Way3

    <label>@c[2]</label>

    Welcome to back if any question with my code:)

    With regards, Angelina Jolie

    Monday, March 5, 2018 8:16 AM