locked
Required Field Validator in Ajax Accordion Pane is not working RRS feed

  • Question

  • User1743618027 posted

    We using Ajax Accordion pane. We dynamically binding ajax accordion from data set. 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.
     
    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>
    Thursday, October 30, 2014 3:33 AM

Answers

  • User-271186128 posted

    Hi RajthilakS24,


    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".

    For this issue, I suggest you could set up validation groups for validators and buttons by using the ValidationGroup property.

    Please refer to the following code.

                <asp:Accordion ID="UserAccordion" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader"
                    HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" FadeTransitions="true" SuppressHeaderPostbacks="true" TransitionDuration="250" FramesPerSecond="40" RequireOpenedPane="false" AutoSize="None">
                    <Panes>
                        <asp:AccordionPane ID="AccordionPane1" runat="server">
                            <Header><a href="#" class="href">New User</a></Header>
                            <Content>
                                <asp:Panel ID="UserReg" runat="server">
                                    UserName:
                                    <asp:TextBox ID="txtuser" runat="server"></asp:TextBox><br />
                                    <asp:RequiredFieldValidator ControlToValidate="txtuser" Text="Note Field is Required" ValidationGroup="one" runat="server" />
    
                                    Password:<asp:TextBox ID="txtpwd" runat="server"></asp:TextBox><br />
                                    <asp:RequiredFieldValidator ControlToValidate="txtpwd" Text="Note Field is Required" ValidationGroup="one" runat="server" />
    
                                    <asp:Button ID="btnsubmit" runat="server" ValidationGroup="one" Text="Save" />
                                </asp:Panel>
                            </Content>
                        </asp:AccordionPane>
                        <asp:AccordionPane ID="AccordionPane2" runat="server">
                            <Header><a href="#" class="href">User Detail</a></Header>
                            <Content>
                                <asp:Panel ID="Panel1" runat="server">
                                    <asp:Label ID="lblNotes" runat="server" Text="Notes:"></asp:Label><br />
                                    <asp:TextBox runat="server" ID="txtNotes" Width="100%" TextMode="MultiLine" Height="35px" /><br />
                                    <asp:RequiredFieldValidator ControlToValidate="txtNotes" Text="Note Field is Required" ValidationGroup="two" runat="server" />
    
                                    <asp:Button ID="btnSave" CssClass="searchbutton Accbtnsave" runat="server" ValidationGroup="two" CommandName="Save" Text="Save" />
    
                                </asp:Panel>
                            </Content>
                        </asp:AccordionPane>
                    </Panes>
                </asp:Accordion>

    Best Regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 31, 2014 4:25 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 3, 2014 11:21 PM

All replies

  • User-271186128 posted

    Hi RajthilakS24,


    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".

    For this issue, I suggest you could set up validation groups for validators and buttons by using the ValidationGroup property.

    Please refer to the following code.

                <asp:Accordion ID="UserAccordion" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader"
                    HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" FadeTransitions="true" SuppressHeaderPostbacks="true" TransitionDuration="250" FramesPerSecond="40" RequireOpenedPane="false" AutoSize="None">
                    <Panes>
                        <asp:AccordionPane ID="AccordionPane1" runat="server">
                            <Header><a href="#" class="href">New User</a></Header>
                            <Content>
                                <asp:Panel ID="UserReg" runat="server">
                                    UserName:
                                    <asp:TextBox ID="txtuser" runat="server"></asp:TextBox><br />
                                    <asp:RequiredFieldValidator ControlToValidate="txtuser" Text="Note Field is Required" ValidationGroup="one" runat="server" />
    
                                    Password:<asp:TextBox ID="txtpwd" runat="server"></asp:TextBox><br />
                                    <asp:RequiredFieldValidator ControlToValidate="txtpwd" Text="Note Field is Required" ValidationGroup="one" runat="server" />
    
                                    <asp:Button ID="btnsubmit" runat="server" ValidationGroup="one" Text="Save" />
                                </asp:Panel>
                            </Content>
                        </asp:AccordionPane>
                        <asp:AccordionPane ID="AccordionPane2" runat="server">
                            <Header><a href="#" class="href">User Detail</a></Header>
                            <Content>
                                <asp:Panel ID="Panel1" runat="server">
                                    <asp:Label ID="lblNotes" runat="server" Text="Notes:"></asp:Label><br />
                                    <asp:TextBox runat="server" ID="txtNotes" Width="100%" TextMode="MultiLine" Height="35px" /><br />
                                    <asp:RequiredFieldValidator ControlToValidate="txtNotes" Text="Note Field is Required" ValidationGroup="two" runat="server" />
    
                                    <asp:Button ID="btnSave" CssClass="searchbutton Accbtnsave" runat="server" ValidationGroup="two" CommandName="Save" Text="Save" />
    
                                </asp:Panel>
                            </Content>
                        </asp:AccordionPane>
                    </Panes>
                </asp:Accordion>

    Best Regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 31, 2014 4:25 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 3, 2014 11:21 PM