disable RequiredFieldvalidator

送分小仙女□ 提交于 2021-02-08 10:24:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!