Solved

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

Posted on 2015-01-21
7
120 Views
Last Modified: 2015-01-29
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
0
Comment
Question by:penlandt
  • 3
  • 3
7 Comments
 
LVL 24

Assisted Solution

by:mankowitz
mankowitz earned 500 total points
ID: 40563564
include

type="date"

in the comparevalidator. See if that helps.
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40563610
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

0
 
LVL 1

Author Comment

by:penlandt
ID: 40565746
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.  :-(
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 24

Expert Comment

by:mankowitz
ID: 40567300
can you post the whole asp page?
0
 
LVL 1

Author Comment

by:penlandt
ID: 40567313
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

0
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
ID: 40569333
I've been looking around to see if I can find a solution. One interesting thing is that the date comparitor only works when you use .ToShortDateString(). Is it possible to change your stored procedure to output the date in that format? (i.e. without the time, just the date)
0
 
LVL 1

Author Comment

by:penlandt
ID: 40569700
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now