jQuery Validation plugin in ASP.NET Web Forms

后端 未结 11 2092
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 14:56

I would really like use the jQuery Validation plugin in my ASP.NET Web Forms application (not MVC). I find it easier than adding asp validators everywhere and setting the co

11条回答
  •  情歌与酒
    2020-11-27 14:56

    A great way to do this is to use:

    <%= textbox.Name %> or <%= textbox.ClientId %> whenever you need to reference a server item.

    i.e.

    var phoneNumb = $('#<%= tPhone.ClientID %>').val(); 
    

    or

    $("#signupForm").validate({
            rules: { 
                    <%= username.Name %>: {
                            required: true,
                            minlength: 2
                    }, },
            messages: { 
                    <%= username.Name %>: {
                            required: "Please enter a username",
                            minlength: "username at least 2 characters"
                    }, 
            }.
    

    .......

提交回复
热议问题