articles

Home / DeveloperSection / Articles / CustomValidator Control in ASP.Net

CustomValidator Control in ASP.Net

Pushpendra Singh9821 11-Nov-2010

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">
</asp:CustomValidator>


Properties:

ClientValidationFunction

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

ControlToValidate

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

  

OnServerValidate

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)
}
</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

When we enter even number then page will execute

CustomValidator Control in ASP.Net


Updated 04-Mar-2020

Leave Comment

Comments

Liked By