具有行为ID验证的Ajax验证callout扩展器

时间:2015-07-09 13:29:40

标签: ajax validation

我已经在我的页面中为所有页面控件定义了Ajaxvalidatoncalloutextender控件和唯一的行为ID。

<ajaxToolkit:ValidatorCalloutExtender ID="vceNotProgress" runat="server" TargetControlID="revInvalidNotClosedProgressValue" BehaviorID="b_vceNotProgress">
                        </ajaxToolkit:ValidatorCalloutExtender>
                        <ajaxToolkit:ValidatorCalloutExtender ID="vceProgress" runat="server" TargetControlID="revInvalidClosedProgressValue" BehaviorID="b_vceProgress">
                        </ajaxToolkit:ValidatorCalloutExtender>

我在客户端点击提交按钮验证,如下

function ValidatePage() 
                        {
                            if (typeof (Page_Validators) == "undefined") return;
                            var noOfValidators = Page_Validators.length;
                            var Page_Callout = new Array(2);
                            Page_Callout[0] = "b_vceNotProgress"; -- behaviour ID
                            Page_Callout[1] = "b_vceProgress"; -- behaviour ID
                            for (var validatorIndex = 0; validatorIndex < noOfValidators; validatorIndex++) {
                                var validator = Page_Validators[validatorIndex];
                                ValidatorValidate(validator);
                                if (!validator.isvalid) {
                                    showValidatorCallout($find(Page_Callout[validatorIndex]));
                                    return false;
                                }
                            }
                            return true;
                        }

我的问题:我不想像Page_Callout [0],Page_Callout [1]那样对数组进行硬编码。我需要填充基于数组                             在页面中的可见控件(即分配行为ID)上。

1 个答案:

答案 0 :(得分:0)

if (typeof (Page_Validators) == "undefined") return;

        var noOfValidators = Page_Validators.length;
        var count = 0;
        var Page_Callout = [];
        for (var i = 0; i < Page_Validators.length; i++) {
            Page_Callout[Page_Callout.length++] = Page_Validators[i]._behaviors != null ? Page_Validators[i]._behaviors[0]._id : "";
            count++;
        }

        for (var validatorIndex = 0; validatorIndex < noOfValidators; validatorIndex++) {
            var validator = Page_Validators[validatorIndex];

            ValidatorValidate(validator);

            if (!validator.isvalid) {
                showValidatorCallout($find(Page_Callout[validatorIndex]));
                return false;
            }
        }
        return true;
    }

    function hideValidatorCallout() {
        AjaxControlToolkit.ValidatorCalloutBehavior._currentCallout.hide();
    }

    function showValidatorCallout(currrentCallout) {
        AjaxControlToolkit.ValidatorCalloutBehavior._currentCallout = currrentCallout;
        AjaxControlToolkit.ValidatorCalloutBehavior._currentCallout.show(true);
    }