title: Passing variable to server-side then back to client side without postback or reload
body: <p>Is there a way to pass values from client side to server-side, server side process this value, then return it to client side without reload or postback?</p>
  
  <p>I am using ajax to pass the value to server side. Here is my client side code:</p>
  
  <pre><code>var baseUrl = '&lt;%= ResolveUrl("~/") %&gt;';
  $.ajax({
      type: "POST",
      url: baseUrl + "Pages/TeamTimeTest/teamtime.aspx/setjson",
      contentType: "application/json; charset=utf-8",
      data: JSON.stringify({
          strpath: $("#hdnfld").val()
  
      }),
      success: function (data) {
      alert(data);
      },
      error: function (response) {
          console.log(response);
      }
  });
  </code></pre>
  
  <p>Here is my code behind code:</p>
  
  <pre><code>[WebMethod(EnableSession = true)]
  public static string setjson(string strpath)
  {
      HttpContext.Current.Session["strDwnPath"] = strpath;
      var val = HttpContext.Current.Session["strDwnPath"].ToString();
      return val;
  }
  </code></pre>
  
  <p>It returns undefined for me. But when I reload it gives me the correct value. Is there a chance that I could have that value even without reloading?</p>