问题
I have RequiredFieldvalidator and I want in certain cases to disable it.
this is the RequiredFieldvalidator:
<asp:RequiredFieldValidator ID="RfvHul" runat="server" ErrorMessage="Error" ControlToValidate="txtBox" Display="None"></asp:RequiredFieldValidator>
and I've tried to do this but all these lines of code gave me Page_IsValid = false
$("#RfvHul").attr("disabled", true);
ValidatorEnable(document.getElementById("<%=RfvHul.ClientID%>"), false);
document.getElementById("RfvHul").Enabled = false;
$("#RfvHul").attr("Enabled", false);
Thanks for the help!
回答1:
You can't just disable it client side and expect the server side code to know about it. You'll have to repeat your disabling logic server side prior to calling Validate().
回答2:
I found the below code working for me.
Requiredfieldvalidator.Enabled = False
The project I am working has all the fields visible but based on certain conditions, validation has to be disabled.
The backend language I am using is VB but frontend side it's the same.
来源:https://stackoverflow.com/questions/44306224/disable-requiredfieldvalidator