locked
RequiredFieldValidator not displaying with AsyncPostBackTrigger on textbox control RRS feed

  • Question

  • User1115159512 posted

    I have a textbox control which is in an Update panel and have the autopostback as TRUE, logic in the TextChanged event and AsyncPostBackTrigger in the Trigger section.

    <asp:UpdatePanel ID="UpdatePanel2" runat="server">

             <ContentTemplate>

                    <asp:RequiredFieldValidator
                         ID="RfvTextBox1"
                         ValidationGroup="Update"
                         runat="server"
                         Display="Dynamic"
                         class="label label-danger"
                         ControlToValidate="txtBox1"
                         SetFocusOnError="true"
                         Font-Size="Medium"
                         Text="Required Field">
                    </asp:RequiredFieldValidator>

                   <asp:TextBox
                         ID="txtBox1"
                         runat="server"
                         CssClass="form-control"
                         TextChanged="txtBox1_TextChanged"
                         autopostback="true">
                   </asp:TextBox>

             </ContentTemplate>


             <Triggers>
                  <asp:AsyncPostBackTrigger ControlID="txtBox1" EventName="TextChanged" />
              </Triggers>

    </asp:UpdatePanel>

    VB Code

    Protected Sub txtBox1_TextChanged(sender As Object, e As EventArgs) Handles txtBox1.TextChanged

         'Business logic

    End Sub

    What is happening, when I tab out of the control with no value in it, the RFV text displays briefly and then disappears. If I don't autopostback it works, otherwise it disappears. It obviously has to do with the autopostback, has anyone encountered this before and if so, what solution did you use?

    For now I have MacGyver'd it by adding a label control with some logic in the TextChanged event on the autopostback but would prefer to use the RFV.

    In addition, I am also using a RegularExpressionValidator with the textbox control and it behaves the same way with the autopostback.

    Thank you for your help,

    William

    Friday, July 20, 2018 11:24 AM

Answers

  • User1115159512 posted

    That is perfect, works like a charm.

    Comments below helped me:

    AnnaLady

    Re: Textbox autopostback and requiredfield

    11-14-2007 05:26 AM|LINK

    If you want to validate your AutoPostBacked TextBoxes, you have to call the Page.Validate() method on the OnTextChanged event.

    That way, your ErrorMessages won't disappear after the PostBack.

    Thank you very much for your help mudassarkhan, much appreciated.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 20, 2018 2:38 PM

All replies

  • User1115159512 posted

    That is perfect, works like a charm.

    Comments below helped me:

    AnnaLady

    Re: Textbox autopostback and requiredfield

    11-14-2007 05:26 AM|LINK

    If you want to validate your AutoPostBacked TextBoxes, you have to call the Page.Validate() method on the OnTextChanged event.

    That way, your ErrorMessages won't disappear after the PostBack.

    Thank you very much for your help mudassarkhan, much appreciated.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 20, 2018 2:38 PM
  • User-1171043462 posted

    Please mark my reply as Answer for others to get reference and help.

    Sunday, July 22, 2018 9:53 AM