• In this article we will learn how to use Customvalidator in or what is Customvalidator in or why Customvalidator in with example.
  • Description:

The CustomValidator control allows you to create a validation control with customized validation logic for both the client side and the server side validation.

Let’s see a small example of Customvalidator:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="customvalidator.aspx.cs"
Inherits="AspDotNet.customvalidator" %>
<!DOCTYPE html>
<html xmlns="">
<head runat="server">
   <script type="text/javascript">
       function validateLength(sender, args) {          
           if (args.Value.length < 6)
               return args.IsValid = false;
               return args.IsValid = true;
   <form id="form1" runat="server">
        Password (Client Side):
    <asp:TextBox runat="server" id="txtPassword"  TextMode="Password" />
  <br />
  <asp:customvalidator clientvalidationfunction="validateLength" forecolor="Red"
  errormessage="Password cannot be less than 6 characters."
controltovalidate="txtPassword"    runat="server" >
<br />
<br />
         Password (Server Side):
 <asp:TextBox runat="server" id="txtpwd"  TextMode="Password"/>
<br />
  <asp:customvalidator  forecolor="Red"
errormessage="Password cannot be less than 6 characters." controltovalidate="txtpwd"
runat="server" OnServerValidate="Password_Validate" Display="Dynamic">
        <br />
        <br />
                 <asp:button text="Validate" id="btnvalidate" runat="server">





using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AspDotNet
    public partial class customvalidator : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)
        protected void Password_Validate(object source, ServerValidateEventArgs e)
            if (e.Value.Length <6)
                e.IsValid = false;
                e.IsValid = true;




How to use customvalidator in Asp.Net

I hope this article will help to you.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like