Asp.net Validation Agent disables button form input

We have a form with a number of required fields. When I am in the required field and I press the enter key, the form is not submitted. However, if I am in a field that is not required, pressing the enter key leaves the form. This is problematic because submitting the form is what triggers the validation in order to display the validation summary at the top. If I am in the required field, it does not run this check. It seems to run his own check and display my error text (which is just an asterisk), but people don’t see this.

Does anyone know why an optional input field introduces a form, but a mandatory key input field will not?

+5
source share
1 answer

From what you described, it looks like you are using server side validation. Try setting it EnableClientScriptto false in the validator, which will disable client-side validation.

If this is not enough, you can override the check when you click the submit button as follows:

<script type="text/javascript">
    validateForm = function(){
        var isValid = Page_ClientValidate("");
        if (isValid){
            //some custom logic if needed
        }
        return true; //do the postback even if validation fails?
                     //otherwise return isValid
    }
</script>
<asp:Button ID="Button1" runat="server" OnClientClick="return validateForm();" ... />
0
source

All Articles