2014-10-28 83 views
0

我有這樣的客戶端功能:ASP.NET和jQuery遠程驗證:驗證功能不叫

$(document).ready(function() { 
    var validate = $("#<%=Page.Form.ClientID%>").validate({ 
     errorElement: 'span',     
     rules: { 
      <%=txtMemberShipNumber.ClientID %> : { 
         required: true, 
         remote: function() { 
          return { 
           url: "/TestForm.aspx/IsMembershipNumberValid", 
           type: "POST", 
           contentType: "application/json; charset=utf-8", 
           dataType: "json", 
           data: JSON.stringify({ value: $('#<%=txtMemberShipNumber.ClientID %>').val() }), 
           dataFilter: function (data) { 
            var msg = JSON.parse(data); 
            if (msg.hasOwnProperty('d')) 
             return msg.d; 
            else 
             return msg; 
           } 
          } 
         }, 
        }, 
       }, 
       messages: { 
        <%=txtMemberShipNumber.ClientID %> : { 
         required: "Account number is Required", 
         remote: "Invalid", 
        }, 
       }, 
       onkeyup:false, 
       onblur: true, 
       onfocusout: function (element) { $(element).valid() } 
}); 

})

...這證實了這一控制:

<input name="ctl00$MainContent$txtMemberShipNumber" type="text" id="MainContent_txtMemberShipNumber" class="textboxStyle" placeholder="Membership Number" /> 

的問題是驗證碼永遠不會被調用。我已經在Firefox和Chrome中測試過它。

我錯過了什麼嗎?

回答

0

我想通了。

而不是

<%= txtMemberShipNumber.ClientID%>:{

...你應該使用

<%= txtMemberShipNumber。 的UniqueID%>:{