Javascript CheckBoxList CustomValidator ClientValidationFunction仅在第二次提交和后续提交时运行

Javascript CheckBoxList CustomValidator ClientValidationFunction仅在第二次提交和后续提交时运行,javascript,asp.net,checkboxlist,customvalidator,Javascript,Asp.net,Checkboxlist,Customvalidator,我有一个动态添加到DNN页面的用户控件 此用户控件基于CheckBoxList(另一个基于CheckBoxList的自定义控件,它在Pre_呈现中只有一点代码来获取有关当前用户的信息),并且可能需要使用验证器。在控件上,我有一个CustomValidator,它的ClientValidationFunction也在控件上设置为javascript块 它工作得很好。很好,事实上。。。除了第一次单击提交按钮 复选框列表是用一个简单的DataSource=x,DataBind。。。胡说八道。。。在VB

我有一个动态添加到DNN页面的用户控件

此用户控件基于CheckBoxList(另一个基于CheckBoxList的自定义控件,它在Pre_呈现中只有一点代码来获取有关当前用户的信息),并且可能需要使用验证器。在控件上,我有一个CustomValidator,它的ClientValidationFunction也在控件上设置为javascript块

它工作得很好。很好,事实上。。。除了第一次单击提交按钮

复选框列表是用一个简单的DataSource=x,DataBind。。。胡说八道。。。在VB代码后面。ASCX端的控件非常简单。但是,第一次单击包含此控件的页面上的submit按钮时,它不会启动ClientValidationFunction。第二次,成功了。第三次,工作

在下面,查找my ASCX的全部内容:

<%@ Control Language="vb"
    Inherits="MyCustom.Modules.WebApps.WebAppsFormBuilderControls.WebAppsFormBuilder_Controls_CustomCheckboxList"
    CodeFile="WebAppsFormBuilder_Controls_CustomCheckboxList.ascx.vb"
    AutoEventWireup="false" Explicit="True" %>

<script type="text/javascript">
    function ValidateCheckboxList(source, args) {
        //window.alert('starting');

        var chkListModules = document.getElementById('<%= cbValue.ClientID %>');
        var chkListinputs = chkListModules.getElementsByTagName("input");

        for (var i = 0; i < chkListinputs.length; i++) {
            if (chkListinputs[i].checked) {
                args.IsValid = true;
            }
        }
        args.IsValid = false;

        //window.alert('IsValid = ' + args.IsValid);
    }
</script>

<myCustom:CheckBoxList ID="cbValue" runat="server" />
<asp:Literal ID="Literal1" runat="server">
    &nbsp;<font color="red" bold="true">*</font>&nbsp;
</asp:Literal>
<asp:CustomValidator runat="server"
    ForeColor="Red" ID="cvCheckBoxList"
    ClientValidationFunction="ValidateCheckboxList"
    ErrorMessage="At least one item must be selected." />

函数ValidateCheckboxList(源,参数){
//window.alert(“启动”);
var chkListModules=document.getElementById(“”);
var chkListinputs=chkListModules.getElementsByTagName(“输入”);
对于(变量i=0;i