custom validater using asp.net with java script

Customervalidator (Client side)
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
        function IsEven(source, args)
        {
            if (args.Value % 2 == 0) {
                args.IsValid = true;}
            else {  args.IsValid = false;}
        }
    </script>
</head>
<div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="TextBox1"
            ErrorMessage="please enter even no" ClientValidationFunction="IsEven"></asp:CustomValidator>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="IsEven" />
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
Customervalidator (Server side)
Custom text:<br />
<asp:TextBox runat="server" id="txtCustom"/>
<asp:CustomValidator runat="server" id="cusCustom" controltovalidate="txtCustom" onservervalidate="cusCustom_ServerValidate" errormessage="The text must be exactly 8 characters long!" />
<br /><br/>



protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (args.Value.Length== 8)
            args.IsValid = true;
        else
            args.IsValid = false;
    }
===========================================


Comments

Popular posts from this blog

How to write Pure java script Program?