我在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 inpuut,请在此按钮旁边显示错误!
<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>
答案 0 :(得分: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
控件
<强> Validation Summary Control 强>
示例:强>
<asp:ValidationSummary ID="ValidationErrors" runat="server"
DisplayMode="BulletList" HeaderText="There are some errors on the page./>