Solved

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

Posted on 2015-01-21
7
119 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

17 Experts available now in Live!

Get 1:1 Help Now