ASP.NET
Custom Validator
Client-side validation
Server-side validation
Troubleshooting

ASP.NET Custom Validator Client side Server Side validation not firing

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

When an ASP.NET CustomValidator does not fire, the cause is usually not the validator itself. It is usually one of the surrounding conditions: the page never validated, the validator is in the wrong validation group, the client JavaScript function name is wrong, or server validation was bypassed by control flow.

Make Sure the Control Is Wired Correctly

A working CustomValidator needs the right properties and handler names.

aspx
1<asp:TextBox ID="txtAge" runat="server" />
2
3<asp:CustomValidator
4    ID="cvAge"
5    runat="server"
6    ControlToValidate="txtAge"
7    ClientValidationFunction="validateAge"
8    OnServerValidate="cvAge_ServerValidate"
9    ErrorMessage="Age must be at least 18"
10    ValidateEmptyText="true" />

And the matching client script:

html
1<script>
2function validateAge(sender, args) {
3    var age = parseInt(args.Value, 10);
4    args.IsValid = !isNaN(age) && age >= 18;
5}
6</script>

And the server handler:

csharp
1protected void cvAge_ServerValidate(object source, ServerValidateEventArgs args)
2{
3    if (int.TryParse(args.Value, out var age))
4        args.IsValid = age >= 18;
5    else
6        args.IsValid = false;
7}

If any of these names or signatures do not match, validation will quietly fail to run.

Check the Validation Group

If your submit button uses a ValidationGroup, the validator and the input control must be in the same group.

A very common bug is having the button validate one group while the CustomValidator belongs to another or to no group at all.

Server Validation Only Happens When Page Validation Runs

Server-side validation does not magically execute on every postback. It runs when validation is triggered, either automatically by a validating control or explicitly through Page.Validate().

csharp
1protected void btnSave_Click(object sender, EventArgs e)
2{
3    Page.Validate();
4    if (!Page.IsValid)
5        return;
6
7    // save logic here
8}

If the button has CausesValidation="false", the validator will not run unless you call Page.Validate() yourself.

Client Validation Depends on Script Availability

If client-side validation is not firing, check:

  • the JavaScript function name matches exactly
  • the script is present on the page
  • there are no browser console errors stopping execution
  • unobtrusive or script-manager setup is not broken

Client validation is convenience. Server validation is the real safety net.

ValidateEmptyText Matters

By default, some validators do not run on empty input. If you want your custom logic to inspect empty values too, set ValidateEmptyText="true" as shown earlier.

Without that, you may think the validator is broken when it is simply skipping blank input by design.

Debug One Layer at a Time

A practical troubleshooting order is: confirm the page posts back, confirm Page.Validate() runs, confirm the server handler executes, and only then debug the client script. That sequence prevents you from chasing JavaScript problems when the real issue is that validation was never triggered at all.

Layered debugging is much faster than changing markup and script at the same time.

Keep Server Validation Even When Client Validation Works

Client-side validation improves responsiveness, but it is never the trust boundary. Browsers can disable scripts, skip validation, or submit handcrafted requests. The server handler should therefore always be treated as the real enforcement path.

Common Pitfalls

The biggest mistake is forgetting that CustomValidator depends on the full validation flow around it, not just on one server method.

Another issue is mismatched validation groups between the validator and the submit button.

A third problem is relying only on the client-side function and never confirming that server-side validation still runs correctly.

Summary

  • Verify the validator markup, JavaScript function, and server handler names all match.
  • Make sure the validator and the triggering control use the same ValidationGroup.
  • Call Page.Validate() when validation is not triggered automatically.
  • Treat client-side validation as convenience, not as the only enforcement layer.
  • Use ValidateEmptyText when empty inputs should still run through your custom logic.

Course illustration
Course illustration

All Rights Reserved.