jQuery验证插件在ASP.NET Web窗体 [英] jQuery Validation plugin in ASP.NET Web Forms

查看:116
本文介绍了jQuery验证插件在ASP.NET Web窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的想用jQuery验证插件,在我的ASP.NET Web窗体应用程序(不MVC)。我觉得比任何地方添加ASP验证和设置,以验证在所有这些领域的控制更加容易。

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 control to validate field on all of them.

我只是有一些问题都设置类这样的类=所需的电子邮件,我觉得有事情做与主窗体标签内有一个表单标签的时候。

I am just having some issues both when setting the class like this class="required email" which I think has something to do with having a form tag within the main form tag.

使用这一个asp的控制变得错位的名称调用JQuery验证时,我也遇到问题

I also run into issues when calling the jquery validate using the names which become mangled in an asp control

// validate signup form on keyup and submit
$("#signupForm").validate({
    rules: { 
        username: {
            required: true,
            minlength: 2
        }, },
    messages: { 
        username: {
            required: "Please enter a username",
            minlength: "username at least 2 characters"
        }, 
    }.

.......

        <p>
            <label for="username">
                Username</label>
            <input id="username" name="username" />
        </p>

由于这种

<asp:TextBox ID="tbUsername"  runat="server"></asp:TextBox>

呈现为

<input name="ctl00$ContentPlaceHolder1$tbUsername" type="text" id="ctl00_ContentPlaceHolder1_tbUsername" />

和轧液的名称。我可以用得到的ClientID &LT;%= tbUsername.ClientID%GT; 但CLIENTNAME是行不通的。

and mangles the name. I can get the ClientID using <%=tbUsername.ClientID %>but that doesnt work with ClientName

有没有人有使用与asp.net jquery的验证插件的成功呢?
如果是关于使用多种形式就像使用seprate验证组是什么?
谢谢

Has anyone had any success using the jquery validator plugin with asp.net? If so what about using multiple forms much like using seprate validation groups? thanks

推荐答案

您可以检出规则添加功能,但基本上这里就是你可以做什么:

You can checkout the rules add function, but basically here's what you can do:

jQuery(function() {
    // You can specify some validation options here but not rules and messages
    jQuery('form').validate(); 
    // Add a custom class to your name mangled input and add rules like this
    jQuery('.username').rules('add', { 
        required: true, 
        messages: { 
            required: 'Some custom message for the username required field' 
        } 
    });
});

<input name="ctl00$ContentPlaceHolder1$tbUsername" type="text" id="ctl00_ContentPlaceHolder1_tbUsername" class="username" />

此方式无需担心由web表单引擎生成的蹩脚的标识符。

This way no need to worry about the crappy identifiers generated by the webforms engine.

这篇关于jQuery验证插件在ASP.NET Web窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆