Friday, 24 February 2012

Use of ClientValidationFunction of CustomValidator in asp.net

DESIGN VIEW

 <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="up" runat="server">
    <ContentTemplate>
    <center>
    <table>
    <tr><td>Name</td><td>
    <asp:TextBox ID="tb" runat="server"></asp:TextBox>
    </td></tr>
     <tr><td>Password</td><td>
     <asp:TextBox ID="tb1" TextMode="Password"  runat="server"></asp:TextBox>
     <asp:CustomValidator ID="CustomValidator1" runat="server"  ControlToValidate="tb1" Display="None"  ClientValidationFunction="xx" ErrorMessage="Password length between 6 to 8 charecter long"></asp:CustomValidator>
         <asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" TargetControlID="CustomValidator1" runat="server"></asp:ValidatorCalloutExtender>
     </td></tr>
      <tr><td>&nbsp;</td><td><asp:Button ID="btn" runat="server" Text="Save" Width="80" />&nbsp;<asp:Button ID="Button1" runat="server" Text="Reset" Width="80" /></td></tr>
    </table>
    </center>
    </ContentTemplate>
    </asp:UpdatePanel>

ADD THIS CODE ON HEADER TAG:
<script language="javascript" type="text/javascript">
    function xx(oSrc, args)
    {
        args.IsValid = (args.Value.length > 5 && args.Value.length<9);
    }
</script>

No comments:

Post a Comment