---
title: "CustomValidator Control in ASP.Net"  
description: "CustomValidator control is used to validate an input control with user-defined function either from server side or client side.      Properties:Client"  
author: "Pushpendra Singh"  
published: 2010-11-11  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/199/customvalidator-control-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# CustomValidator Control in ASP.Net

[CustomValidator](https://www.mindstick.com/forum/49/customvalidator-in-asp-dot-net) control is used to validate an input control with user-[defined function](https://www.mindstick.com/interview/2294/what-is-the-difference-between-a-user-defined-function-and-a-stored-procedure) either from [server side](https://www.mindstick.com/forum/143/close-popup-window-by-server-side-code) or [client side](https://www.mindstick.com/forum/160418/what-are-the-best-practices-for-securely-storing-bearer-tokens-on-the-client-side).\

```
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator"></asp:CustomValidator>
```

## \

**[Properties](https://yourviews.mindstick.com/view/81845/now-it-s-possible-to-predict-properties-of-any-molecule):**

| ClientValidationFunction | Specifies the name of the client-[side validation](https://www.mindstick.com/interview/33573/explain-client-and-server-side-validation) script function to be executed. |
| --- | --- |
| ControlToValidate | The id of the control to validate |
| [Error Message](https://www.mindstick.com/forum/23174/error-message-the-page-you-are-requesting-cannot-be-served-because-of-the-extension-configuration) | The text to display in page when [validation fails](https://www.mindstick.com/forum/34291/how-to-raise-a-callback-when-asp-dot-net-mvc-client-validation-fails). Note: This text will also be displayed in the validation control if the [Text property](https://www.mindstick.com/forum/161/problem-in-getting-text-property-for-sender-object) is not set |
|  |  |
| OnServerValidate | Specifies the name of the server-side validation script function to be executed |

![CustomValidator Control in ASP.Net](https://www.mindstick.com/mindstickarticle/caf86b07-9ea7-4b79-9ad2-03f310a71c0f/images/ec60a2f4-6d20-4dbe-95fa-beef4e2ff08a.png)

```
  <script type="text/javascript">function validatenumber(oSrc,args){args.IsValid = (args.Value % 2 == 0)}</script>   <asp:CustomValidator ID="CustomValidator1" runat="server"            ControlToValidate="TextBox1" ErrorMessage="enter only even number"             ClientValidationFunction="validatenumber"></asp:CustomValidator>
```

Validatenumber function is used to check that enter number is even or odd.It accepts only even nomber

When you will enter odd number then error message will show.

![CustomValidator Control in ASP.Net](https://www.mindstick.com/mindstickarticle/caf86b07-9ea7-4b79-9ad2-03f310a71c0f/images/9b226cf9-b45b-4f04-b337-72e065fa7fcf.png)

When we enter even number then page will execute

![CustomValidator Control in ASP.Net](https://www.mindstick.com/mindstickarticle/caf86b07-9ea7-4b79-9ad2-03f310a71c0f/images/8a72eeb0-1907-4c6b-8eea-2e7bf4c44484.png)

---

Original Source: https://www.mindstick.com/articles/199/customvalidator-control-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
