title: Make ASP.NET AJAX function call synchronous
body: <p>I have an ASP.NET form that calls a web service using ASP.NET AJAX. How do I make the call synchronous?</p>
  
  <p>// test.aspx</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function GetDescription(){
          var code = document.getElementById("&lt;%=txtCode.ClientID%&gt;").value;
          var description = 
              MyNamespace.MyService.GetDescription(
                  code, onSuccessGetDescription, null, null);
          return false;
      }
  
      function OnSuccessGetDescription(result){
          var txtDescription = 
              document.getElementById("&lt;%=txtDescription.ClientID%&gt;");
      }
  &lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(document).ready(//function () {
  
          $('#&lt;%=cmdSave.ClientID%&gt;').click(function (e) {
              e.preventDefault();
              if (Page_ClientValidate()){
                  // Populate jQuery.UI dialog box with code and description
                  // and then
                  $("#confirm-dialog").dialog("open");
              }
          });
  
      }
  &lt;/script&gt;
  
  &lt;asp:TextBox ID="txtCode" /&gt;
  &lt;asp:TextBox ID="txtDescription" /&gt;
  &lt;asp:Button ID="cmdSave" /&gt;
  </code></pre>
  
  <p>// test.aspx.cs</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      txtCode.Attributes["onblur"] = "GetDescription();";
  }
  </code></pre>
  
  <p>The answers to this question that I have seen say that I should set the async attribute to false, but I don't see how to do that here.
  <a href="https://stackoverflow.com/questions/1957600/asp-net-ajax-pagemethods-synchronous-call-and-retrieval-of-results">ASP.Net Ajax - PageMethods Synchronous call and retrieval of results</a> says that it can't be done. I am trying to get a second opinion.</p>
  
  <p>If I can't make the call synchronous, would it be legal to make GetTransaction poll until the OnSuccess function returns? What would be an efficient (i.e. not CPU-intensive) way to do that?</p>