CustomValidator control is used to validate an input control with user-defined function either from server side or client side.

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



Specifies the name of the client-side validation script function to be executed.


The id of the control to validate

Error Message

The text to display in page when validation fails. Note: This text will also be displayed in the validation control if the Text property is not set



Specifies the name of the server-side validation script function to be executed


CustomValidator Control in ASP.Net

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

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

When we enter even number then page will execute

CustomValidator Control in ASP.Net

  Modified On Mar-22-2018 07:24:43 AM

Leave Comment