Avatar of Todd Penland
Todd Penland
Flag for United States of America asked on

Compare Validator Incorrectly Identifying Date from Previous Year as Greater Than Date From Current Year

I have a Compare Validator on my page which is supposed to insure that the second date selected in a pair of drop down lists is greater than or equal to the first date selected.  Here's the validator:

<asp:CompareValidator CssClass="ErrorMessage" ID="CompareValidator1" runat="server" ErrorMessage="Must be later than, or equal to From date." ControlToCompare="ddIncludeFrom" ControlToValidate="ddIncludeTo" SetFocusOnError="True" Operator="GreaterThanEqual"></asp:CompareValidator>

This afternoon I discovered however that if I select a date from September 2014 in the first box and a date from February 2015 in the second, the validator incorrectly detects an error.  (See embedded screenshot.)

Any idea how to fix this?

Error screenshot
ASP.NET

Avatar of undefined
Last Comment
Todd Penland

8/22/2022 - Mon
SOLUTION
mankowitz

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ramkisan Jagtap

Yes, Including Type="Date" will solve your problem. It will work for MM/dd/YYYY format.
for other formats you need to change the Culture property of the page. e.g. for dd/mm/yyyy format change it to en-GB in the @Pagedirective of the Page as show below:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Culture = "en-GB" %>

Open in new window

Todd Penland

ASKER
Unfortunately it hasn't worked.  Here's my new Compare Validator:

<asp:CompareValidator Type="Date" CssClass="ErrorMessage" ID="CompareValidator1" runat="server" ErrorMessage="Must be later than, or equal to From date." ControlToCompare="ddIncludeFrom" ControlToValidate="ddIncludeTo" SetFocusOnError="True" Operator="GreaterThanEqual"></asp:CompareValidator>

It is still returning the same error with the same input as the original post.  :-(
mankowitz

can you post the whole asp page?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Todd Penland

ASKER
Sure.  Here it is:

<%@ Page Title="Schedule Search" Language="C#" MasterPageFile="~/MasterPages/Main.master" AutoEventWireup="true" CodeFile="ScheduleSearch.aspx.cs" Inherits="Members_ScheduleSearch" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cpHC" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMC" Runat="Server">
    <h2><asp:Literal id="Literal1" runat="server"></asp:Literal>: Schedule Search</h2>
    <asp:UpdatePanel runat="server">
        <ContentTemplate>
            <asp:Label CssClass="C3DEFormLabel" ID="lblMemberName" runat="server" Text="Member:"></asp:Label>
            <asp:DropDownList CssClass="C3DEFormText" ID="ddMemberName" runat="server" AppendDataBoundItems="True" DataSourceID="dsMemberNames" DataTextField="Name" DataValueField="Id" AutoPostBack="true" OnSelectedIndexChanged="ddMemberName_SelectedIndexChanged">
                <asp:ListItem></asp:ListItem>
            </asp:DropDownList>
            <br />
            <asp:Label CssClass="C3DEFormLabel" ID="lblIncludeFrom" runat="server" Text="Include From:"></asp:Label>
            <asp:DropDownList CssClass="C3DEFormText" ID="ddIncludeFrom" runat="server" AppendDataBoundItems="True" DataSourceID="dsIntervalStartDates" DataTextField="IntervalStartDate" DataValueField="IntervalStartDate" OnSelectedIndexChanged="ddIncludeFrom_SelectedIndexChanged" AutoPostBack="True">
                <asp:ListItem></asp:ListItem>
            </asp:DropDownList>
            <br />
            <asp:Label CssClass="C3DEFormLabel" ID="lblIncludeTo" runat="server" Text="Include To:"></asp:Label>
            <asp:DropDownList CssClass="C3DEFormText" ID="ddIncludeTo" runat="server" AppendDataBoundItems="True" DataSourceID="dsIntervalStartDates" DataTextField="IntervalStartDate" DataValueField="IntervalStartDate" OnSelectedIndexChanged="ddIncludeTo_SelectedIndexChanged" AutoPostBack="True">
                <asp:ListItem></asp:ListItem>
            </asp:DropDownList>
            <asp:CompareValidator Type="Date" CssClass="ErrorMessage" ID="CompareValidator1" runat="server" ErrorMessage="Must be later than, or equal to From date." ControlToCompare="ddIncludeFrom" ControlToValidate="ddIncludeTo" SetFocusOnError="True" Operator="GreaterThanEqual"></asp:CompareValidator>
            <br /><br />
            <asp:Button CssClass="SubGridButton" ID="btnGroupList" runat="server" Text="Group List" OnClick="btnGroupList_Click" />
            <asp:Button CssClass="SubGridButton" ID="btnScheduleCreate" runat="server" Text="Create Schedule" OnClick="btnScheduleCreate_Click" />
            <asp:Button CssClass="SubGridButton" ID="btnSearch" runat="server" Text="Search" Enabled="false" OnClick="btnSearch_Click"/>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:SqlDataSource ID="dsMemberNames" runat="server" ConnectionString="<%$ ConnectionStrings:dbCS %>" SelectCommand="spClientGroupMemberSortNames" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:SessionParameter Name="GroupID" SessionField="GroupID" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsIntervalStartDates" runat="server" ConnectionString="<%$ ConnectionStrings:dbCS %>" SelectCommand="spClientGroupScheduleStartDates" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:SessionParameter Name="GroupID" SessionField="GroupID" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>

Open in new window

ASKER CERTIFIED SOLUTION
mankowitz

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Todd Penland

ASKER
This particular application requires the time as well but that's good to know (that it only works with short dates).  I'll probably have to write my own code to do the validation then.