0

I have an ASP.NET form where I have an ImageButton control as follows (please note that this only part of a bigger form):

<asp:CheckBox runat="server" ID="checkbox1" Text="Validate" Enabled="false" />
<asp:TextBox runat="server" ID="textbox1" MaxLength="30" />
<asp:RequiredFieldValidator ID="validator1" ControlToValidate="textbox1" Text="required!" runat="server" ValidationGroup="group1" />
<asp:ImageButton ID="button1" runat="server" Width="24" ValidationGroup="group1" />

Using Javascript, I could disable and enable the RequiredFieldValidator as follows:

function test() {
  var checkbox1 = document.getElementById("<%=checkbox1.ClientID %>");
  var ckOwnerIsOperator = document.getElementById('<%=ckOwnerIsOperator.ClientID %>');

  if (checkbox1.checked)
    ValidatorEnable(validator1, false);
}

What I am looking for is an event that fires before the validation on the button when the button is clicked. I know I could do this on checkbox click event, but it is not what I need. The checkbox click event has a problem where I lose the validator state if another control triggered an async postback, so I want the test() function to be called before the page validation occurs.

Thank you all

1 Answer 1

1

You could add onclientclick="test()" to the button.

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

2 Comments

That worked... for some reason I thought I tried that, but apparently not! Thank you
Maybe you used onclick like I originally had before my edit. It is pretty easy to confuse the two when coding fast.

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.