views:

45

answers:

1

For validating login field (at register form) I use customValidator

        <asp:CustomValidator id="uniqueLoginValidator" class="validator" runat="server" ControlToValidate="tbUserName" ErrorMessage="Login duplicate" ClientValidationFunction="LoginValidate"/>

For validate login I need consume wcf, so decide use web-methods

   <script type="text/javascript">
   function LoginValidate(oSrc, args) {
       var login = $(".loginField").val();
       PageMethods.ValidateLogin(login,OnRequestComplete, OnRequestError);
       return;
   }
   function OnRequestComplete(result, userContext, methodName) {
       return;
   }

   function OnRequestError(error, userContext, methodName) {
       if (error != null) {
           alert(error.get_message());
       }
  </script>

My web-method like:

   [WebMethod]
   public static bool ValidateLogin(string login)
   {
        //wcf consuming
        return res;
    }

For successfull validating I should setup args at ClientValidationFunction, but I get result validation only at callBack. So how can I setup args for validation work.

+1  A: 

The problem is that the line

PageMethods.ValidateLogin(login,OnRequestComplete, OnRequestError);

initiates a asynchronous call to the page method and return immediately: it does not block until that call has completed.

See http://www.codeproject.com/KB/validation/Async_CustomValidator.aspx for a discussion and a solution (a new validator control).

Andreas Paulsson
Thanks. Solution was finded at http://www.codeproject.com/KB/ajax/SyncPMValidation.aspx by your answer!!!
Andrew Kalashnikov