http://www.w3.org/1999/xhtml"> function checkIssueType(source, args) { var chkListaTipoModificaciones = d_c#中web应用程序如何设置requiredfieldvalidator组件">
当前位置:   article > 正文

c# web 如何使用RequiredFieldValidator控件验证CheckBoxList_c#中web应用程序如何设置requiredfieldvalidator组件

c#中web应用程序如何设置requiredfieldvalidator组件

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CheckboxlistDemo._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script language="javascript" type="text/javascript">
        function checkIssueType(source, args) {
            var chkListaTipoModificaciones = document.getElementById('<%= IssueTypeCheckBox.ClientID %>');
            var chkLista = chkListaTipoModificaciones.getElementsByTagName("input");
            for (var i = 0; i < chkLista.length; i++) {
                if (chkLista[i].checked) {
                    args.IsValid = true;
                    return;
                }
            }
            args.IsValid = false;
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td>
                    <asp:CheckBoxList ID="IssueTypeCheckBox" runat="server" RepeatDirection="Horizontal">
                        <asp:ListItem Value="1">Hardware</asp:ListItem>
                        <asp:ListItem Value="2">Software </asp:ListItem>
                        <asp:ListItem Value="3">Mechanical</asp:ListItem>
                        <asp:ListItem Value="4">Others</asp:ListItem>
                    </asp:CheckBoxList>
                </td>
                <td>
                    <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="*" ClientValidationFunction="checkIssueType"></asp:CustomValidator>
                </td>
            </tr>
            <tr>
            <td><asp:Button runat="server" ID="btn" Text="Submit"/></td>
            <td> </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/701473
推荐阅读
相关标签
  

闽ICP备14008679号