RequiredFieldValidator requires the user to double-click

I have a simple web form with a text box and the RequiredFieldValidator associated with it. When the RequiredFieldValidator error is triggered, the user needs to double-click the link to submit the form. The first click clears the error, the second actually fires when the button is pressed. Is this expected behavior?

<asp:RequiredFieldValidator ID="reqFieldCloseComment" ControlToValidate="tbCloseComment" ValidationGroup="ChangeStatus" ErrorMessage="Please enter a reason" Display="Dynamic" runat="server"></asp:RequiredFieldValidator> <asp:TextBox ID="tbCloseComment" runat="server" CausesValidation="true" TextMode="MultiLine" Height="107px" Width="400px"></asp:TextBox> <asp:Button ID="btnCloseRequestFinal" Text="Finish" CssClass="CloseReqButton" runat="server" ValidationGroup="ChangeStatus" /> 

I tried adding CausesValidation to the text box according to the sentence found in a Google search, and this does not help.

EDIT It seems that there should not always be a double click to disable the event. As the text is entered into the text field and then the focus is removed from the text field, the RequiredFieldValidator error message disappears, and the form requires only one click.

+7
source share
2 answers

This is because the code that clears the error message is run when the text field loses focus. So what happens:

  • Enter text in the field
  • You click on the button that triggers the onblur event in the text field, running the code to check the field value again and delete the error message
  • Now there are no errors in the verification, so clicking the button submits the form again.

When you first press the tab key (or basically do everything that takes the focus off the text field), then the onblur script is executed and the error is removed so that when you click the submit button, it is ready to work.

+1
source

I had the same problem with CompareValidator and it turned out that the problem disappeared when I changed the Display property from Dynamic to Static. Hope that helps

+5
source

All Articles