title: How to perform server-side validation before submit
body: <p>Form contains input element. Entered value is validated using server callback from blur
  event andler.</p>
  
  <p>If wrong value is entered and submit button is pressed, form is submitted with wrong value:
  Validate method is not completed but form submit action method is executed.</p>
  
  <p>How to force Validate() method to be completed before form submit method is executed ?</p>
  
  <p>jquery, jqueryUI, ASP .NET MVC2 are used.</p>
  
  <pre><code>&lt;form id="Form" class='form-fields' method='post'   action='/Report/Render'&gt;
    &lt;input id='test' name='test' value='test' /&gt;
    &lt;input id='_submit' type='submit' value='Show report' /&gt;
  &lt;/form&gt;
  
      $('#test').bind({
          blur: function (e) {
              if (!Validate(e.target)) {
                  cancel(e);
              }
          }
      });
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>As required in BobTodd comment here is validate method:</p>
  
  <pre><code>function Validate(elem) {
  var i,
    res;
  $.ajax('Grid/Validate' );
     {
         data: $("#Form").serializeArray(),
         //async: false,
         type: 'POST',
         error: function (jqXHR, textStatus, errorThrown) {
             elem.skipBlur = true;
             errorMessage(decodeErrorMessage(jqXHR.responseText === undefined ? '' : jqXHR.responseText,
                        textStatus, errorThrown));
             elem.focus();
             elem.select();
             elem.skipBlur = false;
             elem.ischanged = true;
             res = false;
         },
         success: function (data) {
             elem.ischanged = false;
             for (i = 0; i &lt; data.length; i += 1) {
                 $('#' + data[i].name).val(data[i].value);
             }
             res = true;
         }
     });
  return false; //  res;
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Update2</strong></p>
  
  <p>All answers suggest to prevent submit method to run if validation is not preformed. This provides very bad user experience: validate takes some time. User shoudl press <strong>two times</strong> in submit button for form to submit. How to allow form to submit using single click ? Maksing Validate() sync method alllws this but i'm not sure is using sync call reasonable solution for this.</p>