Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. more cookie

more cookie

Scheduled Pinned Locked Moved C#
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hotthoughtguy
    wrote on last edited by
    #1

    protected void btnAdd_Click(object sender, EventArgs e) { Response.Cookies["message"].Value = "Hello World"; Response.Cookies["message"].Expires = DateTime.Now.AddDays(1); btnAdd.Text = Response.Cookies["message"].Value; Button1.Text = Response.Cookies["message"].Value; } protected void Button1_Click(object sender, EventArgs e) { if (Response.Cookies["message"] == null) Button1.Text = "null"; else Button1.Text = Response.Cookies["message"].Value; } when btnAdd)Click is executed it sets Button1.Text = btnAdd.Text = "Hello World"; but when Button1_Click is executed it sets Button1.Text = String.Empty. Why?

    P 1 Reply Last reply
    0
    • H hotthoughtguy

      protected void btnAdd_Click(object sender, EventArgs e) { Response.Cookies["message"].Value = "Hello World"; Response.Cookies["message"].Expires = DateTime.Now.AddDays(1); btnAdd.Text = Response.Cookies["message"].Value; Button1.Text = Response.Cookies["message"].Value; } protected void Button1_Click(object sender, EventArgs e) { if (Response.Cookies["message"] == null) Button1.Text = "null"; else Button1.Text = Response.Cookies["message"].Value; } when btnAdd)Click is executed it sets Button1.Text = btnAdd.Text = "Hello World"; but when Button1_Click is executed it sets Button1.Text = String.Empty. Why?

      P Offline
      P Offline
      PSK_
      wrote on last edited by
      #2

      hotthoughtguy wrote:

      if (Response.Cookies["message"] == null) Button1.Text = "null"; else Button1.Text = Response.Cookies["message"].Value;

      refer the cookie from request object rather than response.

      if (Request.Cookies["message"] == null)
      Button1.Text = "null";
      else
      Button1.Text = Request.Cookies["message"].Value;

      Regards, Prakash Kalakoti

      H 1 Reply Last reply
      0
      • P PSK_

        hotthoughtguy wrote:

        if (Response.Cookies["message"] == null) Button1.Text = "null"; else Button1.Text = Response.Cookies["message"].Value;

        refer the cookie from request object rather than response.

        if (Request.Cookies["message"] == null)
        Button1.Text = "null";
        else
        Button1.Text = Request.Cookies["message"].Value;

        Regards, Prakash Kalakoti

        H Offline
        H Offline
        hotthoughtguy
        wrote on last edited by
        #3

        yes its working with Request. thanks again

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups