Compare validator in dd/mm/yyyy format we need to change the Culture property of the page to “en-GB” in the @Page directive of the asp.net Page. if you are using the Master page concept and if the compare validator are not worked for dd/mm/yyyy format then you can set the page culture in code behind page of the aspx page
<%@ Page Language="C#" AutoEventWireup="false"CodeFile="CompareValidator.aspx.cs"
Inherits="CompareValidator" Culture = "en-GB" %>
<!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 id="Head1" runat="server">
<title>Compare Validator for dd/mm/yyyy format in asp.net using compare validator.
</title>
</head>
<body>
<form id="form1" runat="server">
From Date:
<asp:TextBox ID="txtFromDate" runat="server" Text="18/02/2015"></asp:TextBox>
To Date:
<asp:TextBox ID="txtToDate" runat="server" Text="19/12/2016"></asp:TextBox><br />
<asp:CompareValidator ID="CompareValidator1" ValidationGroup="Date"ForeColor="Red"
runat="server" ControlToValidate="txtFromDate"ControlToCompare="txtToDate" Operator="LessThan"
Type="Date" ErrorMessage="Start date must be less than End date."></asp:CompareValidator>
<br />
<asp:Button ID="btnCompare" runat="server" Text="Compare"ValidationGroup="Date" />
</form>
</body>
</html>
No comments:
Post a Comment