1

I'm using Web Forms Validators to prevent user from leave blank required inputs, but in my form some inputs may be disabled in some circumstance and need to disable validation for this textBox and dropdownlists.I try to using JQuery and remove some attributes to disable the validations, for instance:

Disable

$("#VDrpLeaveKind").css("visibility", "hidden").attr("data-val-enabled", false);

Enable

$("VDrpLeaveKind").removeAttr("data-val-enabled").css("visibility", "visible");

It's work when input disabled, but after clicking on the submit button, validation error message will appears again. There is Validation code:

<span data-val-controltovalidate="DrpLeaveKind" data-val-errormessage="error message" data-val-validationgroup="vacation" id="VDrpLeaveKind" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="0" style="color:Red;font-size:Smaller;visibility:hidden;">error message</span>

I try some other ways like change validationgroup, or use Causevalidation but nothing. If further information needs, please inform me. Thank you in advance.

1 Answer 1

2

If you want to enable/disable a validator clientside, you want to call ValidatorEnable and pass it the validator control and then a boolean to enable/disable it:

ValidatorEnable(requiredFieldValidator, false);

Reference link.

Sign up to request clarification or add additional context in comments.

2 Comments

It's Work for me, but the JavaScript Intellisense does not contain ValidatorEnable.
The best option is to disable the validations use ValidatorEnable(requiredFieldValidator, false); and to enable use $("Input")[0].enabled = true;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.