Users Pricing

articles

Home Articles CustomValidator Control in ASP.Net – MindStick

CustomValidator Control in ASP.Net

Pushpendra Singh 10834 11 Nov 2010 Updated 04 Mar 2020

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


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md