1

I am creating a webpage for clients to register their companies with our organization, they need to confirm if they are authorized to provide us with such information, so I have two checkboxes for them to tick to confirm, i used custom validation for the checkboxes, when i click the submit button it gives me an error "Javascript runtime error: 'validatecheckboxes_clientvalidate' is undefined

here is my asp.net code

<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please click checkbox to confirm" ForeColor="Red"                       
    ClientValidationFunction="validateCheckBoxes_ClientValidate"
    OnServerValidate="validateCheckBoxes_ServerValidate">
</asp:CustomValidator>

here is my c# code

protected void validateCheckBoxes_ServerValidate(object source, ServerValidateEventArgs args)
{
    if (CheckBox1.Checked)
        args.IsValid = true;
    else
        args.IsValid = false;
}

Please tell me what I am missing

1
  • 2
    What you´re missing is not the server side validation method, but the client side javascript code you reference in "ClientValidationFunction="validateCheckBoxes_ClientValidate", or did you just forget to post it? Commented Oct 29, 2015 at 15:53

1 Answer 1

1

validatecheckboxes_clientvalidate needs to be a client side function written in Javascript not a function in C#

<script language="javascript"> 
   function validatecheckboxes_clientvalidate(source, arguments)
   {
        ...
   }
</script>

Source: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.clientvalidationfunction(v=vs.110).aspx

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

Comments

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.