AlexanderD
AlexanderD

Reputation: 626

jQuery Validation with Web Forms

I don't know what's wrong but when clicking on the textbox I alway get

Uncaught TypeError: Cannot read property 'settings' of undefined

Here's my code (simplified for clarity):

<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>

I already tried

The problem only uccurs when using a Master page

May this be due to the fact that my referred element is a <div>? I am using Web Forms, so I can't use another <form> tag

Upvotes: 1

Views: 1540

Answers (1)

Syed Ali Taqi
Syed Ali Taqi

Reputation: 4974

As described here and here, you must use a form for jQuery Validate plugin. I can't tell of a specific plugin that'll meet your requirements but you can have a look at this.

Upvotes: 1

Related Questions