gra*_*der 5 asp.net validation jquery jquery-validate
所以我已经编写了一个自定义的jQuery验证器方法.它与一个或多个单独的下拉列表相关联.(我在asp.net,顺便说一句)
jQuery.validator.addMethod("dropdownBoxHasItemSelected", function (value, select, arg) {
    var returnValue = false;
    var selectedIndex = $(select).prop("selectedIndex");
    if (selectedIndex != 0) {
        returnValue = true;
    }
    return returnValue;
}, "Please select a item.");
所以这不是我的问题.
我有一些必须在"页面级别"完成的验证.或者也许在"GridView"级别是一种更好的方式来表达它.
这是一个场景:(我正在使用虚拟数据来使解释更容易,也就是说,我真的没有玩具和食品)
我有一个网格视图.
Column A of the gridview is of no consequence of this, but it exists.
Column B of the gridview has a DropDownList for "FavoriteToy". 
Column C of the gridview has a DropDownList for "FavoriteFood".
所以规则就是这样的.
对于gridview中的每一行:
You must pick a FavoriteToy or a FavoriteFood for each row.
You can pick a FavoriteToy OR a FavoriteFood, but not both on the same row.
If you pick a FavoriteToy of "TeddyBear" in RowX, none of the other rows can have TeddyBear chosen. (Aka, each row must have a distinct FavoriteToy chosen)
If you pick a FavoriteFood of "AppleButter" in RowX, none of the other rows can have AppleButter chosen. (Aka, each row must have a distinct FavoriteFood chosen)
如果需要,可以将新行添加到gridview.还有一个"删除"按钮,以防用户已经用尽所有FavoriteToy和FavoriteFood组合.
现在,我已经编写了所有验证逻辑(使用jQuery语法来检查值并循环所有内容)就好了.
我正在寻找有关如何使用jQuery.validator.addMethod连接"网格视图整体验证器"的建议.
我想我可以线它高达ASP:标签(类型的"输入" =在客户端侧"文本"),以使错误味精弹出那里.
或者,网格视图在客户端呈现为"表".
一般建议吗?
================================================== ==================
到目前为止我放了什么:
asp:net控件:
<asp:HiddenField ID="hidGridViewValidatorPlaceHolder" runat="server" />
和以下方法
jQuery.validator.addMethod("gridViewValiatorMethod", function (value, select, arg) {
    var returnValue = true;
    var errorMsg = SuperValidationWrapper();
    if (errorMsg != "") {
        alert(errorMsg);
        returnValue = false;
    }
    return returnValue;
}, "Please address the issues in the gridview.");
SuperValidationWrapper()具有所有loopty循环.我返回一个串联的字符串,有任何问题.我不喜欢那样,但这就是我所做的.
警报框为您提供详细信息,以及文本"请解决gridview中的问题".出现是否有任何问题.
任何改进都表示赞赏.
验证器实际上是为了验证字段而设计的,但由于您不想验证字段,因此无法将表达式绑定到字段。
您确实需要将“页面验证”逻辑放入提交处理程序中
http://docs.jquery.com/Plugins/Validation/validate#options
| 归档时间: | 
 | 
| 查看次数: | 474 次 | 
| 最近记录: |