我在Repeater中使用更新面板。我需要更新面板包含验证。验证已经到位,但每个小组都被解雇了。我需要它才能应用于被访问的Panel。
<asp:Repeater ID="rptComments"
runat="server"
OnItemDataBound="rptComments_OnItemDataBound"
OnItemCommand="rptComments_OnItemCommand">
<HeaderTemplate>
<ul class="comments">
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:UpdatePanel ID="updatePanelReply" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:PlaceHolder ID="plcForm" runat="server">
<div class="errors">
<asp:ValidationSummary ID="nestedCommentsValidation" ValidationGroup="nestedSubmit" runat="server" cssClass="validation" ForeColor="Red" />
</div>
<label>Name<sup>*</sup></label>
<asp:TextBox ID="tbReplyName" runat="server" cssClass="styledInput"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="rfv_tbReplyName"
runat="server"
Display="None"
ControlToValidate="tbReplyName"
InitialValue=""
ErrorMessage="Please enter your name."
ValidationGroup="nestedSubmit">
</asp:RequiredFieldValidator>
<asp:Button ID="btnButton" runat="server" Text="Button" CssClass="submit-button" CommandName="SubmitReply" ValidationGroup="nestedSubmit" />
</asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
答案 0 :(得分:0)
您是否在不同的面板中使用不同的验证组?验证组的重点是验证器仅验证同一组中的控件。
答案 1 :(得分:0)
我最终取出验证组并在OnItemCommand事件中处理它。可能有一种更为流畅的方式,但这对我有用。
if (String.IsNullOrEmpty(tbReplyName.Text.ToString().Trim()))
strValidationMessage = "<li>Please enter your name.</li>";
Literal ltrErrorMessage = (Literal)e.Item.FindControl("ltrErrorMessage");
ltrErrorMessage.Text = strValidationMessage;