How to disable RequiredFieldValidator in script

I have a TextBox with RequiredFieldValidator on my page. I also have a link that calls plain javascript.

<asp:TextBox ID="TextBox1" runat="server" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" /> 
<asp:LinkButton   ID="Link1" runat="server" OnClientClick="DoSomething(); return false;" CausesValidation="false"Text="Do" />

function DoSomething() {
textbox1.val("blah"); }

When a user enters something into a text field, and then deletes that text and focuses the next control - then the validator is triggered. The user can then use a link that adds text using javascript. TextBox1 is no longer empty, but RequiredFieldValidator still displays an error message. How to prevent this?

+5
source share
3 answers

you can use javascript function ValidatorEnable

ValidatorEnable(document.getElementById('<%= ValidatorID.ClientID %>'), true);
+6
source

CustomValidator , RequiredFieldValidator. CustomValidator .

+1

The whole point of validators is that they should be used both for server-side and client-side validation.

If you only want to check on the server side, do not use the validator and just make sure that the values ​​are valid and report an error.

0
source

All Articles