I am using an Update Panel within a Repeater. I need for the Update Panel to contain validation. The validation is in place but is getting fired for each Panel. I need it to only be applied to the Panel being accessed.

<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>
有帮助吗?

解决方案 2

I ended up taking out the validation group and handling it in the OnItemCommand event. There may be a slicker way of doing it, but this worked for me.

if (String.IsNullOrEmpty(tbReplyName.Text.ToString().Trim()))
            strValidationMessage = "<li>Please enter your name.</li>";

Literal ltrErrorMessage = (Literal)e.Item.FindControl("ltrErrorMessage");
            ltrErrorMessage.Text = strValidationMessage;

其他提示

Are you using different validation groups in your different panels? The whole point of the validation group is that the validators will only validate the controls that are in the same group.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top