title: Executing JavaScript function in Code behind -- How to Get the Return Value in Code Behind
body: <p>I have following JavaScript function, Which call Jquery JSON function and get the DateTime with respect to timezone. This works fine.</p>
  
  <pre><code>  &lt;script type="text/javascript"&gt;
      function JSFunctionName() {
          $(document).ready(function () {
              var timezone = "US/Central";
              $.getJSON("http://json-time.appspot.com/time.json?tz=" + timezone + "&amp;callback=?",
  function (data) {
      if (data.hour &lt; 12) {
          //alert(data.hour + ':' + data.minute); // want to return this value data.hour + data.minute
          //document.getElementById('&lt;%=HiddenField1.ClientID %&gt;').value = data.hour + ':' + data.minute;// this does not work
      }
  })
          });
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Now I am calling this Javascription function in Code behind on onclick of button</p>
  
  <pre><code>&lt;asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /&gt;
  </code></pre>
  
  <p><strong>Code behind</strong></p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      Page.ClientScript.RegisterStartupScript(this.GetType(),
          "alert", "JSFunctionName();", true);
      // here I need the DateTime value that is get from JSON
      //Response.Write(HiddenField1.Value); 
  }
  </code></pre>
  
  <p>How can I return the value from Javascript to code behind immediate after call of <code>Page.ClientScript.RegisterStartupScript</code></p>
  
  <p>Please note I have try to set the value in HiddenField, but its not working. you can see in the comment.</p>
  
  <p>Any idea or alternative solution will be appreciated.</p>
  
  <p>Thanks</p>