我在aspx页面上有一个带有可编辑行的转发器。该行有一个文本框和一个与之关联的必填字段验证器。在“保存”按钮上单击该行,必填字段值将触发,它与页面顶部的验证结果相关联。
现在我在转发器下面有一个带有文本框和保存按钮的面板。在点击此面板顶部的链接按钮时,使用jquery show方法“打开”此面板。 此texbox不会触发所需的字段验证器。我对此文本框有一个不同的验证摘要;因为我只需点击其保存按钮就可以触发验证。
所以我有这样的代码,
<asp:ValidationSummary ID="validationSummary" ValidationGroup="ValidationGroup1" EnableClientScript="true" runat="server" />
<asp:ValidationSummary ID="validationSummary1" ValidationGroup="ValidationGroup2" EnableClientScript="true" runat="server" />
<asp:Repeater ID="Teams" runat="server" OnItemCommand="ItemCommand" OnItemDataBound="ItemDataBound">
<HeaderTemplate>
<table >
<tr>
<th>
<asp:Label ID="lbTeamNameHeader" runat="server" Text="TeamNameHeader"></asp:Label></th>
<th></th> </tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:TextBox ID="txtTeamName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "txtTeamName")%>' />
<asp:RequiredFieldValidator ID="reqdFieldValTeamName" ErrorMessage="Field cannot be blank" ValidationGroup="ValidationGroup1" runat="server" Display="None" ControlToValidate="txtTeamName"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regularExprTeamName" ErrorMessage="Invalid input for the team name" ValidationGroup="ValidationGroup1" Display="None" ControlToValidate="txtTeamName" runat="server" ValidationExpression="^[a-zA-Z0-9]+$"></asp:RegularExpressionValidator>
</td>
<td>
<asp:Panel ID="panelSave" runat="server" Visible="false">
<asp:LinkButton ID="linkbuttonSave" runat="server" CommandName="Save" ValidationGroup="ValidationGroup1" Text="SAVE" />
<asp:LinkButton ID="linkbuttonCancel" runat="server" CommandName="Cancel" Text="CANCEL" />
</asp:Panel>
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
<asp:LinkButton ID="linkbuttonAddTeam" runat="server" Text="Add New Team" />
<div id="AddPanelDiv" style="display:none;">
<asp:TextBox ID="txtAddTeam" runat="server" />
<asp:RequiredFieldValidator ID="reqdFieldValAddTeam" ErrorMessage="Field cannot be blank" ValidationGroup="ValidationGroup2" runat="server" Display="None" ControlToValidate="txtAddTeam"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regularExprValAddTeam" ErrorMessage="Invalid format" ValidationGroup="ValidationGroup2" Display="None" ControlToValidate="txtAddTeam" runat="server" ValidationExpression="^[a-zA-Z0-9]+$"></asp:RegularExpressionValidator>
<asp:LinkButton ID="linkbuttonCancel" runat="server" Text="CANCEL"></asp:LinkButton>
<asp:LinkButton ID="linkbuttonSaveNewTeam" runat="server" OnClick="linkbuttonSaveNewTeam_OnClick" Text="SAVE" CausesValidation="true" />
</div>
为什么地板上的验证器会发生火灾?点击该保存按钮后,它会直接进入页面方法onclick。
如果我删除验证组并单击转发器中的保存,则会触发!但这不是我想要的......
答案 0 :(得分:0)
您的第二个按钮上缺少ValidationGroup="ValidationGroup2"
。
<asp:LinkButton ID="linkbuttonSaveNewTeam" runat="server" OnClick="linkbuttonSaveNewTeam_OnClick"
Text="SAVE" CausesValidation="true" ValidationGroup="ValidationGroup2" />