Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2015-01-21
7
Medium Priority
?
130 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 24

Assisted Solution

by:mankowitz
mankowitz earned 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

730 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