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

前端之家收集整理的这篇文章主要介绍了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相关文章