Solved

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

Posted on 2015-01-21
7
126 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 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
Industry Leaders: 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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