【问题标题】:Checkbox Required Validator复选框必需的验证器
【发布时间】:2014-01-20 01:22:48
【问题描述】:

我在 asp.net 中开发了一个应用程序,在我的页面上有一个必填字段的复选框,我在验证后进行编码,但按保存验证没有调用。

<asp:CheckBox ID="ChkContent" runat="server" Text=" I hereby certify that the information above is true and accurate."
                        Font-Bold="true" />
                    <asp:CustomValidator ID="Custom1"  CssClass="errorTop" ClientValidationFunction="CheckBoxValidation" runat="server"
            ErrorMessage="You must select this box to proceed" ></asp:CustomValidator> 

保存按钮代码是

   <asp:Button ID="BtnSaveMiscDetail" ValidationGroup="AddMisc" CssClass="buttonGrid"
                            runat="server" Text="Save" Width="60px" OnClick="BtnSaveMiscDetail_Click" />

客户端验证码是

function CheckBoxValidation(oSrouce, args) {
        var myCheckBox = document.getElementById("ContentPlaceHolder1_MiscDetails1_ChkContent");

        if (myCheckBox.checked) {

            args.IsValid = true;

        }
        else
            args.IsValid = false;

    }

验证函数没有调用。

【问题讨论】:

  • 在您的自定义验证器控件中添加ValidationGroup="AddMisc"

标签: c# javascript asp.net validation checkbox


【解决方案1】:

在您的自定义验证器控件中添加ValidationGroup="AddMisc"

<asp:CheckBox ID="ChkContent" runat="server" Text=" I hereby certify that the information above is true and accurate."
                        Font-Bold="true" />
                    <asp:CustomValidator ID="Custom1" 
                          CssClass="errorTop" 
                          ClientValidationFunction="CheckBoxValidation" 
                          runat="server"
                          ErrorMessage="You must select this box to proceed"
                          ValidationGroup="AddMisc">
                    </asp:CustomValidator>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    相关资源
    最近更新 更多