asp.net – 如何在警告框中显示验证控件的错误消息?

我使用4个必填字段验证器,4个正则表达式验证器和4个比较验证器4个文本框.是否可以显示错误消息

验证失败时在警报或消息框中?

如果可能请发送代码示例.

问候,

NSJ

最佳答案
    <form id="form1" runat="server">
    <asp:Label ID="lblNameRequired" runat="server" Text="*Name :"></asp:Label>
    <asp:TextBox ID="txtNameRequired" runat="server" ValidationGroup="Validation"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ControlToValidate="txtNameRequired"
        Display="None" ErrorMessage="Name is Required" ValidationGroup="Validation"></asp:RequiredFieldValidator>
    <br />
    <asp:Label ID="lblGenderRequired" runat="server" Text="*Gender :"></asp:Label>
    <asp:DropDownList ID="ddlGenderRequired" runat="server" ValidationGroup="Validation">
        <asp:ListItem Selected="True" Value="-1">--Select--</asp:ListItem>
        <asp:ListItem Value="0">Male</asp:ListItem>
        <asp:ListItem Value="1">Female</asp:ListItem>
    </asp:DropDownList>
    <asp:CompareValidator ID="CompareValidatorGender" runat="server" ControlToValidate="ddlGenderRequired"
        Display="None" ErrorMessage="Gender is Required" Operator="NotEqual" ValidationGroup="Validation"
        ValueToCompare="-1"></asp:CompareValidator>
    <br />
    <asp:Label ID="lblValidation" runat="server" Text="Fields marked with * are required"></asp:Label>
    <br />
    <asp:Button ID="btnValidate" runat="server" Text="Validate Input" ValidationGroup="Validation" />
    <br />
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
        ShowSummary="False" ValidationGroup="Validation" />
    </form>

您应该在所有验证控件上使用相同的ValidationGroup文本,并使用ValidationGroup和ShowMessageBox =“true”添加ValidationSummary

转载注明原文:asp.net – 如何在警告框中显示验证控件的错误消息? - 代码日志