asp.netcookiesupdatepanelhttpcookieaspbutton

Write & Read cookie within an updatepanel in asp.net


I created a simple asp.net webform project. Trying to read/write a cookie on button_click event in updatepanel.

Hierarchical order of the button:

UpdatePanel > Repeater > Button

Condition of Button Click:

Button click is working wheel. Trigger is working. When i am trying to create a cookie on button click it doesn't work. Do you have an idea why?

Button Click:

protected void mybutton_Click(object sender, EventArgs e)
{
  Button mybutton = sender as Button;
  RepeaterItem rpt = mybutton.NamingContainer as RepeaterItem;
  if(rpt != null)
  {
     HttpCookie newcookie = new HttpCookie("test");
     newcookie.Value= "testvalue";
     Response.Cookie.Add(newcookie);
  }
}

Solution

  • I have searched and tried codes. But still have same issue. Problem is not related with code. Code is working well. Clean your solution, restart visual studio. Stop IIS if it's running.

    Open your project and you will see problem dissapears.

    It works for me. I hope you do.