title: Reading Cookies in C# and ASP.net; the cookie values lags behind
body: <p>I'm having difficulty getting the updated value of the getCookie the second, third, fourth etc. time I change the value of either my txtPrice or ddTaxRate.  It works fine on the first time I hit the calculation but if I change the value of either the txtPrice or the ddTaxRate then I need to hit the calculation button twice to get an updated value for the getCookie.</p>
  
  <pre><code>public partial class _Default : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              //First time the page loads
          }
          else
          {
              HttpCookie myCookie = new HttpCookie("data");
              myCookie.Expires = DateTime.Now.AddHours(12);
  
              //Grab data
              myCookie.Values.Add("price", txtPrice.Text);
              myCookie.Values.Add("tax", ddTaxRate.SelectedItem.Value.ToString());
              Response.Cookies.Add(myCookie);
  
              calculate();
          }
      }
  
      protected void cmdCalculate_Click(object sender, EventArgs e)
      {
      }
  
      protected void calculate()
      {
          if (Request.Cookies["data"] != null)
          {
              HttpCookie getCookie = Request.Cookies["data"];
  
              double price = Convert.ToDouble(getCookie.Values["price"]);
              double taxRate = (Convert.ToDouble(getCookie.Values["tax"]));
              double rate = taxRate / 100;
              double total = (price + (price * rate));
  
              txtNetPrice.Text = Convert.ToString(total);
          }
      }
  }
  </code></pre>
  
  <p>I've seen the getCookie lag behind in value through debugging.  Was wondering if anyone knows how to get an up-to-date value of the getCookie?</p>