2016-03-02 95 views
1

我知道这是一种常见的情况,所以我对它进行了搜索,但对我的情况没有好运。使用Web表单进行jQuery验证

我不知道什么是错误的,但在文本框时,点击我送花儿给人得到

Uncaught TypeError: Cannot read property 'settings' of undefined

这里是我的代码(简化为清楚起见):

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> 

<div id="MessageForm"> 
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 

    <asp:Button ID="Button1" runat="server" Text="doPostBack" /> 
</div> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#MessageForm').validate({ 
      rules: { 
       <%= TextBox1.ClientID %>: { 
         required: true, 
         minlength: 6, 
         maxlength: 25 
        } 
       }, 
       messages:{ 
        <%= TextBox1.ClientID %>: { 
         required: "Please enter the address.", 
         minlength: $.validator.format("The address name must be at least {0} characters."), 
         maxlength: $.validator.format("The address name must not exceed {0} characters.") 
        } 
       }, 
       errorClass: "error-label", 
       wrapper: "li", 
       errorLabelContainer: "#ErrorSection" 
      }); 
     }); 
</script> 

我已经尝试过

  • change <div id="MessageForm"><div id="MessageForm" runat="server">
  • 改变$('#MessageForm').validate$('#MainContent_MessageForm').validate
  • 改变<%= TextBox1.ClientID %>到生成的客户端ID(MainContent_TextBox1)或所产生的名字(搜索Maincontent $ Contenteplaceholder $等)

使用主站时该问题只uccurs页

这可能是由于我的引用元素是<div>? 我使用Web窗体,所以我不能使用其他<form>标签

+0

如上所述[这里](http://stackoverflow.com/questions/4936221/jquery-validate-plugin-on-div)和[这里](http://stackoverflow.com/questions/487430/validate-输入那不是在一个窗体与jQuery的验证插件),你必须使用一个'表格'的jQuery验证插件。我还没有测试,但你尝试[validator.element()](http://jqueryvalidation.org/Validator.element) –

+0

@SyedAliTaqi谢谢,我可以很容易地将元素更改为'

',但它不够。我发现令人难以置信的是,现在人们无法轻易地将jquery验证整合到webforms上。我只是要使用标准的验证器,谢谢。请张贴您的答案 –

回答

1

如上所述herehere,你必须使用一个form jQuery的验证插件。我无法确定哪个插件能满足您的要求,但您可以看看thisthis。希望能帮助到你。