Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am use custom validator for date validation for that i write ClientValidation is
working fine with IE(8.0 version) but it's not working with chrome .please give any suggestion .


following is JavaScript function :

JavaScript
function ValidateDate(source, args) {
  var txtFrom = document.getElementById('<%= txtdate.ClientID%>').value;
            var txtTo = document.getElementById('<%= txtTodate.ClientID%>').value;
            var txtDate = new Date(txtFrom);
            var txtToDate = new Date(txtTo);
            if (txtDate <= txtToDate)
                args.IsValid = true;
            else
                args.IsValid = false;
}
Posted
Updated 16-Dec-12 20:50pm
v2
Comments
[no name] 17-Dec-12 3:18am    
No problem on your code in my computer google chrome.

1 solution

XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <script type="text/javascript">

        function ValidateDate(source, args) {

            var txtFrom = document.getElementById('<%= txtdate.ClientID%>').value;
            var txtTo = document.getElementById('<%= txtTodate.ClientID%>').value;
            var txtDate = new Date(txtFrom);
            var txtToDate = new Date(txtTo);
            if (txtDate <= txtToDate)
                args.IsValid = true;
            else
                args.IsValid = false;
        }
    </script>
    <div>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="Validate" />
        <asp:TextBox ID="txtdate" runat="server"></asp:TextBox>
        <asp:TextBox ID="txtTodate" runat="server"></asp:TextBox>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator"
            ClientValidationFunction="ValidateDate" ValidationGroup="Validate"></asp:CustomValidator><asp:Button ID="Button1"
                runat="server" Text="Button" ValidationGroup="Validate" />
    </div>
    </form>
</body>
</html>


Your Code is working fine, Tested in Chrome Version 23.0.1271.97 m
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900