1

我在 asp 中有注册表单,它有 30 个输入框,它们都有 RequiredFieldValidator 。当用户单击提交时,我如何发现至少有一个输入未填写并在提交按钮和输入控件旁边显示错误?

<fieldset>
        <legend>title :</legend>
        <asp:Table ID="Table3" runat="server">
            <asp:TableRow runat="server">
                <asp:TableCell runat="server"> :</asp:TableCell>
                <asp:TableCell runat="server">
                    <asp:TextBox ID="txtMadrakTahsili" runat="server" CssClass="Width"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" 
            ErrorMessage="*" Display="Dynamic" ControlToValidate="txtMadrakTahsili"></asp:RequiredFieldValidator>
                    </asp:TableCell>
                <asp:TableCell runat="server">reshte :</asp:TableCell>
                <asp:TableCell runat="server">
                    <asp:TextBox ID="txtReshteTahsili" runat="server" CssClass="Width"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator25" runat="server" 
            ErrorMessage="*" Display="Dynamic" ControlToValidate="txtReshteTahsili"></asp:RequiredFieldValidator></asp:TableCell>
                <asp:TableCell ID="TableCell7" runat="server">mahale akhz :</asp:TableCell>
                <asp:TableCell ID="TableCell8" runat="server">
                    <asp:TextBox ID="txtMahalAkhzMadrak" runat="server" CssClass="Width"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server" 
            ErrorMessage="*" Display="Dynamic" ControlToValidate="txtMahalAkhzMadrak"></asp:RequiredFieldValidator></asp:TableCell>
            </asp:TableRow>
            <asp:TableRow runat="server">
                <asp:TableCell runat="server">avg</asp:TableCell>
                <asp:TableCell runat="server">
                    <asp:TextBox ID="txtMoadel" runat="server" CssClass="Width"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator15" runat="server" 
            ErrorMessage="*" Display="Dynamic" ControlToValidate="txtMoadel"></asp:RequiredFieldValidator></asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </fieldset>

如果一个 og 输入未填写,则在此按钮旁边显示错误!

<p style="float:left; clear:both;">
        <asp:Button ID="Button1" runat="server" Text="ثبت اطلاعات" Height="54px" 
            style="margin-right: 0" Width="119px" onclick="Button1_Click" /></p>
4

1 回答 1

2
<asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" 
    ErrorMessage="The textbox is empty" Text="*" 
Display="Dynamic" ControlToValidate="txtMadrakTahsili">

当你使用Text="*"Textbox时,如果您将其放在 附近,它会显示在旁边Textbox

当您想一起显示所有验证错误时,该ErrorMessage属性很有用。

所以如果你想显示Error Messages关联的Textboxes话我建议你使用ASP.NET ValidationSummary控件

验证摘要控制

例子:

<asp:ValidationSummary ID="ValidationErrors" runat="server"
DisplayMode="BulletList" HeaderText="There are some errors on the page./> 
于 2012-09-22T06:51:11.977 回答