title: JSON variable not updating on postback
body: <p>I have a form to edit database values. I register a json variable using <code>ClientScriptManager.RegisterClientScriptBlock</code> on page load and then use it to check for changes to the form and prompt the user to save. In the save button click event I then re-execute the code that registers the json variable so that it contains the changes the user just saved.</p>
  
  <p>The problem I've run into is the json variable is not updating to reflect the changes to the form after the postback. Only after refreshing the page does the json varable update.</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      Property p = Property.GetPropertyById(id);
      PopulateForm(p);
      CreateJson(p);
  }
  
  protected void btnSave_Click(object sender, EventArgs e)
  {
      Property p = Property.GetPropertyById(id);
      p.Price = txtPrice.Text.Trim();
  
      p.Save();
      CreateJson(p);
  }
  
  private void CreateJson(Property p)
  {
      StringBuilder JSONtext = new StringBuilder();
      JSONtext.Append("&lt;script type='text/javascript'&gt;");
      JSONtext.Append("var property = ");
      JSONtext.Append("{");
      JSONtext.Append("\"price\":\"");
      JSONtext.Append(p.Price.ToString());
      JSONtext.Append("};");
      JSONtext.Append("&lt;/script&gt;");
  
      Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jsonVariable", JSONtext.ToString());
  }
  </code></pre>
  
  <p>Is what I'm trying to do even possible?</p>