Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7662555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:49:52+00:00 2026-05-31T13:49:52+00:00

I have a start date and end date field in a form. I have

  • 0

I have a start date and end date field in a form. I have specified format for calender extender. since then, the compare validator is not working. It is always displaying the error message. Please help. I need to show the date in the format “Fri 04 May 2012”.

Start date field:

<asp:TextBox ID="txtStartDate" ReadOnly="true" runat="server" 
    CssClass="textBoxWidth TPRValue" Text='<%#DataBinder.Eval(Container.DataItem, "StartDate", "{0: ddd MM dd, yyyy}")%>'>
</asp:TextBox>
<asp:ImageButton ID="imgBtnStartDate" runat="server" ImageUrl="~/Common/Images/Calendar.GIF" CausesValidation="false" ImageAlign="AbsMiddle" />
<ajax:CalendarExtender ID="StartDateCalendar" TargetControlID="txtStartDate" PopupButtonID="imgBtnStartDate" runat="server" 
    Format="ddd MM dd, yyyy">
</ajax:CalendarExtender>
<asp:CompareValidator ID="startDateCompareValidator" runat="server" ControlToValidate="txtStartDate" ControlToCompare="txtEndDate" Enabled="true" 
    Type="Date" Display="Dynamic" Operator="LessThanEqual"
    Text="Startdate should be <= enddate">
</asp:CompareValidator>

EndDate field:

<asp:TextBox ID="txtEndDate" ReadOnly="true" runat="server" 
    CssClass="textBoxWidth TPRValue" Text='<%#DataBinder.Eval(Container.DataItem, "EndDate", "{0: ddd MM dd, yyyy}")%>'>
</asp:TextBox>
<asp:ImageButton ID="imgBtnEndDate" runat="server" ImageUrl="~/Common/Images/Calendar.GIF" CausesValidation="false" ImageAlign="AbsMiddle" />
<ajax:CalendarExtender ID="EndDateCalendar" TargetControlID="txtEndDate" PopupButtonID="imgBtnEndDate" runat="server" 
    Format="ddd MM dd, yyyy">
</ajax:CalendarExtender>

Compare validator:

<asp:CompareValidator ID="startDateCompareValidator" runat="server" ControlToValidate="txtStartDate" 
    ControlToCompare="txtEndDate" Enabled="true" Type="Date" Display="Dynamic" Operator="LessThanEqual"
    Text="Startdate should be <= enddate">
</asp:CompareValidator>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:49:54+00:00Added an answer on May 31, 2026 at 1:49 pm

    I assume that the CompareValidator does not accept your format.

    The CompareValidator is pretty particular about the dates that it will accept. For example, the following dates are not considered valid:

    • January 1, 2001
    • Jan 1, 2001
    • Fri 04 May 2012

    The CompareValidator requires a date that looks like this:

    • 1/1/2001
    • 1-1-2001
    • 5/4/2012

    http://www.informit.com/articles/article.aspx?p=25461&seqNum=5

    Without having tested it, you could try to use a hidden TextBox(display:none) with the accepted date format as Text. Then set the Validator’s ControlToValidate to the “hiddenfield”. You need to synchronize both TextBoxes’ Text properties with their hiddenfields. Maybe this gives you an idea.

    Edit: Ok, i’ve tried to get it working what i’ve said and actually it is working 🙂
    Maybe there’s some refactoring possible, but have a look yourself.

    To hide the TextBox with the working date format i’ve used CSS:

    <style type="text/css">
        .hidden
        {
            display:none;   
        }
    </style>
    

    These JS-functions are called when the user changes a date via CalendarExtenders:

    <script type="text/javascript">
        function dateChangedStart(sender, args) {
            var selectedDate = sender.get_selectedDate();
            var hiddenStart = $get("txtStartDateHidden");
            var validator = $get("startDateCompareValidator");
            hiddenStart.value = dateToString(selectedDate);
            ValidatorValidate(validator);
        }
        function dateChangedEnd(sender, args) {
            var selectedDate = sender.get_selectedDate();
            var hiddenEnd = $get("txtEndDateHidden");
            var validator = $get("startDateCompareValidator");
            hiddenEnd.value = dateToString(selectedDate);
            ValidatorValidate(validator);
        }
        function dateToString(d) {
            var year = d.getFullYear();
            var month = d.getMonth() + 1; //months are zero based
            var day = d.getDate();
            return year + "/" + month + "/" + day;
        }
    </script>
    

    This is the rest of the sample page:

    <div>
        <asp:TextBox ID="txtStartDate" CausesValidation="false" ReadOnly="true" runat="server">
        </asp:TextBox>
        <asp:TextBox ID="txtStartDateHidden" CssClass="hidden" ValidationGroup="DateCheck" CausesValidation="true" ReadOnly="false" runat="server">
        </asp:TextBox>
        <ajax:CalendarExtender ID="StartDateCalendar" TargetControlID="txtStartDate" runat="server"
            OnClientDateSelectionChanged="dateChangedStart"
            Format="ddd MM dd, yyyy">
        </ajax:CalendarExtender>
        <asp:CompareValidator ID="startDateCompareValidator" runat="server" EnableClientScript="true"
            ControlToValidate="txtStartDateHidden" Display="Static" Operator="LessThanEqual" ValidationGroup="DateCheck"
            ControlToCompare="txtEndDateHidden" Enabled="true" Type="Date" Text="Startdate should be <= enddate">
        </asp:CompareValidator>
        <asp:TextBox ID="TxtEndDate" CausesValidation="false" ReadOnly="true" runat="server">
        </asp:TextBox>
        <asp:TextBox ID="txtEndDateHidden" CssClass="hidden" ValidationGroup="DateCheck" CausesValidation="true" ReadOnly="false" runat="server">
        </asp:TextBox>
        <ajax:CalendarExtender ID="EndDateCalendar" TargetControlID="txtEndDate" runat="server"
            OnClientDateSelectionChanged="dateChangedEnd"
            Format="ddd MM dd, yyyy">
        </ajax:CalendarExtender>
        <asp:Button ID="BtnSubmit" CausesValidation="true" ValidationGroup="DateCheck" runat="server" Text="Submit" />
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a form I have one Date text field and 2 dropdowns: Start time
I have start date and end date. I need to find out the day
I'm using the jQuery datepicker where I have two textboxes (start date / end
In MySQL, If I have a list of date ranges (range-start and range-end). e.g.
I need to have a start and end time widget on a form. i.e.
I have a form where the user will select a date range, and then
I have two Ajax Toolkit calendar extenders. One of them is a start date
I have 2 independent but contiguous date ranges. The first range is the start
I am using Symfony 1.2.9, and I have a form that contains two date
I have a Note object, which has a start_date field (date, required) and an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.