简体   繁体   English

Ajax手风琴窗格中的必填字段验证器不起作用

[英]Required Field Validator in Ajax Accordion Pane is not working

We using Ajax Accordion pane. 我们使用“ Ajax手风琴”窗格。 We dynamically binding ajax accordion from data set. 我们从数据集中动态绑定ajax手风琴。 So we not sure how much pane wil be bind. 因此,我们不确定将绑定多少窗格。

Now we added few textbox and 1 button in each accordion pane which is mandotory so we used required field validator. 现在,在每个手风琴窗格中添加了几个文本框和1个按钮,这是必填项,因此我们使用了必需的字段验证器。

The problem is when i click buton in first pane textbox in first pane showing "It is required" which is fine but even if i typed textbox in first pane. 问题是当我在第一窗格的第一窗格文本框中单击按钮,显示“需要”时,这很好,但是即使我在第一窗格中键入了文本框也是如此。 I am not able to save since textbox in remaining pane showing "It is required". 我无法保存,因为剩余窗格中的文本框显示“必需”。 Please guide me. 请指导我。

<cc1:Accordion ID="accRcvDetails" runat="server" SelectedIndex="-1" ContentCssClass="accordion-content" RequireOpenedPane="false" HeaderCssClass="accordion-header" 
                                     HeaderSelectedCssClass="accordionSelected" OnItemCommand="accRcvDetails_ItemCommand" OnItemDataBound="accRcvDetails_ItemDataBound">

                                     <HeaderTemplate>
     </HeaderTemplate>
                                     <ContentTemplate>
    <td class="searchlabel">
                                                         <asp:Label ID="lblNotes" runat="server" Text="Notes:"></asp:Label>
                                                     </td>
                                                     <td class="searchtext" colspan="3">
                                                         <asp:TextBox runat="server" ID="txtNotes" Width="100%" TextMode="MultiLine" Height="35px" />
                                                         <asp:RequiredFieldValidator ControlToValidate="txtNotes" Text="Note Field is Required" runat="server" />
                                                     </td>
                                                     <td>
     <td style="text-align: right" colspan="8">
                                                         <asp:Button ID="btnSave" CssClass="searchbutton Accbtnsave" runat="server" CommandName="Save" Text="Save" />
                                                     </td>
 </ContentTemplate>


                                 </cc1:Accordion>

You need to mention ValidationGroup for every textbox and button, as you are binding the accordion at runtime, so need to bind ValidationGroup at runtime with some property that has unique/different value for every accordian. 在运行时绑定手风琴时,需要为每个文本框和按钮都提到ValidationGroup,因此需要在运行时将ValidationGroup绑定到每个手风琴具有唯一/不同值的某些属性。 Lets say you are binding accordion with rows of Groups, you can mention groupId in ValidationGroup then. 假设您将手风琴与Groups的行绑定,则可以在ValidationGroup中提及groupId。 Your updated code must looks alike: 更新后的代码必须类似:

 <asp:RequiredFieldValidator ControlToValidate="txtNotes" Text="Note Field is Required" runat="server" ValidationGroup='<%# Eval("GroupId") %>'/>

 <asp:Button ID="btnSave" CssClass="searchbutton Accbtnsave" runat="server" CommandName="Save" Text="Save" ValidationGroup='<%# Eval("GroupId") %>'/>

This way each accordion has its own ValidationGroup and clicking on button will not fire the validators in other accordions 这样,每个手风琴都有自己的ValidationGroup,单击按钮不会触发其他手风琴中的验证器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM