Understanding Required FieldValidator Dynamic Error Indication

Asked 2 years ago, Updated 2 years ago, 131 views

I have a question about asp.net.

I used the RequiredFieldValidator property to verify the input.
Unlike RangeValidator, error verification was not performed dynamically.
Only after being posted back to the server can the RequiredFieldValidator be dynamically validated, do these properties have such controls?

age
    <asp:TextBox ID="Age" runat="server"Text=""></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"ErrorMessage="Required"
        ControlToValidate="Age"></asp:RequiredFieldValidator>
    <asp: RangeValidator Id="RangeValidator1" runat="server" 
        ErrorMessage = "Age ranges from 0 to 15"
        ControlToValidate="Age" InitialValue="Enter text"
        Maximumvalue="15" MinimumValue="1" Type="Integer">
    </asp:RangeValidator>

asp.net

2022-09-30 21:12

1 Answers

You can configure whether the validator works on the client side in the BaseValidator.EnableClientScript property.
However, the default value for this property for RequiredFieldValidator is true.Verification has been performed even if the code in the questionnaire works here, so you should check if there are any other script errors or unexpected postbacks.


2022-09-30 21:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.