C# 如何使用asp.net中特定按钮的验证摘要?
我有一个包含如下所示控件的页面C# 如何使用asp.net中特定按钮的验证摘要?,c#,asp.net,validationsummary,C#,Asp.net,Validationsummary,我有一个包含如下所示控件的页面 <asp:TextBox id="txt_name" runat="server"/> <asp:RequiredFieldValidator ControlToValidate="txt_name" ErrorMessage="Name" Text="*" runat="server"/> <asp:Button id="b1" Text="Submit" runat="server"/> <asp:Bu
<asp:TextBox id="txt_name" runat="server"/>
<asp:RequiredFieldValidator
ControlToValidate="txt_name"
ErrorMessage="Name"
Text="*"
runat="server"/>
<asp:Button id="b1" Text="Submit" runat="server"/>
<asp:Button id="b2" Text="Clear" runat="server"/>
<asp:ValidationSummary
HeaderText="You must enter a value in the following fields:"
DisplayMode="BulletList"
EnableClientScript="true"
runat="server"/>
如何仅对“提交”按钮使用验证摘要?您可以对“清除”按钮使用或
使用CausesValidation
<asp:Button id="b2" Text="Clear" runat="server" CausesValidation="false" />
使用此按钮,b2
将不会触发验证
<asp:TextBox id="txt_name" runat="server"ValidationGroup="check"/>
<asp:RequiredFieldValidator
ControlToValidate="txt_name"
ErrorMessage="Name"
Text="*"
runat="server"/>
<asp:Button id="b1" Text="Submit" runat="server" ValidationGroup="check"/>
<asp:Button id="b2" Text="Clear" runat="server"/>
<asp:ValidationSummary
HeaderText="You must enter a value in the following fields:"
DisplayMode="BulletList"
EnableClientScript="true"
runat="server"/>
在第二种方法中,您可以对要包括在验证中的每个控件使用ValidationGroup
属性。您可以使用或清除按钮
<asp:TextBox id="txt_name" runat="server"ValidationGroup="check"/>
<asp:RequiredFieldValidator
ControlToValidate="txt_name"
ErrorMessage="Name"
Text="*"
runat="server"/>
<asp:Button id="b1" Text="Submit" runat="server" ValidationGroup="check"/>
<asp:Button id="b2" Text="Clear" runat="server"/>
<asp:ValidationSummary
HeaderText="You must enter a value in the following fields:"
DisplayMode="BulletList"
EnableClientScript="true"
runat="server"/>
使用CausesValidation
<asp:Button id="b2" Text="Clear" runat="server" CausesValidation="false" />
使用此按钮,b2
将不会触发验证
<asp:TextBox id="txt_name" runat="server"ValidationGroup="check"/>
<asp:RequiredFieldValidator
ControlToValidate="txt_name"
ErrorMessage="Name"
Text="*"
runat="server"/>
<asp:Button id="b1" Text="Submit" runat="server" ValidationGroup="check"/>
<asp:Button id="b2" Text="Clear" runat="server"/>
<asp:ValidationSummary
HeaderText="You must enter a value in the following fields:"
DisplayMode="BulletList"
EnableClientScript="true"
runat="server"/>
在第二种方法中,您可以对要包括在验证中的每个控件使用ValidationGroup
属性。
<asp:TextBox id="txt_name" runat="server"ValidationGroup="check"/>
<asp:RequiredFieldValidator
ControlToValidate="txt_name"
ErrorMessage="Name"
Text="*"
runat="server"/>
<asp:Button id="b1" Text="Submit" runat="server" ValidationGroup="check"/>
<asp:Button id="b2" Text="Clear" runat="server"/>
<asp:ValidationSummary
HeaderText="You must enter a value in the following fields:"
DisplayMode="BulletList"
EnableClientScript="true"
runat="server"/>
这将与我使用的方法相同。
这将起作用,因为我一直在使用相同的方法