Solved

CompareValidator using TextField with CalendarExtender with format dd/MM/yyyy HH:mm

Posted on 2008-10-29
6
1,773 Views
Last Modified: 2008-12-09
Our project has a standard date format of dd/MM/yyyy HH:mm that I can not change.

I want to allow users to enter in a date into a textbox using the calendar extender.

Furthermore, we need to prevent them from selecting future dates.

Unfortunately the attached code does not work.

Suggestions / solutions?
<asp:CompareValidator 

  ID="CompareValidator1" 

  runat="server" 

  ControlToValidate="textBox1" 

  ErrorMessage="Can not pick future dates" 

  Operator="LessThanEqual" 

  Type="Date">

</asp:CompareValidator>

Open in new window

0
Comment
Question by:Jonathan_Bride
  • 3
  • 3
6 Comments
 
LVL 22

Expert Comment

by:prairiedog
Comment Utility
It is related to the current culture settings because the date format is determined by the culture information your application is using. You can change the culture information on a specific page by adding the culture information in the Page directive:
<%@ Page culture="here" %>
dd/MM/yyyy HH:mm looks like "en-GB", is it right? You can change try this:
<%@ Page culture="en-GB" %>
0
 

Author Comment

by:Jonathan_Bride
Comment Utility
Hi,

en-GB is unfortunately for me "31/10/2008 06:08:28". I need it without the last 28 / ss

http://asp.infoz.hk/App/CultureList.aspx

0
 
LVL 22

Expert Comment

by:prairiedog
Comment Utility
>>>en-GB is unfortunately for me "31/10/2008 06:08:28". I need it without the last 28 / ss

What do you get the value displayed? In the text box after user selects a date from the calendar?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Jonathan_Bride
Comment Utility
the display from user selection is (as per standard format)

dd/MM/yyyy HH:mm

Eng-Gb is

dd/MM/yyyyy HH:mm:ss

minor difference but it does not work as far as i am aware
0
 
LVL 22

Expert Comment

by:prairiedog
Comment Utility
What if you set your CanlendarExtender's Format property to "dd/MM/yyyy HH:mm:ss", will that work for you?
0
 

Accepted Solution

by:
Jonathan_Bride earned 0 total points
Comment Utility
No, it can not have ":ss" at the end as the code behind in this solution automatically changes any date to dd/MM/yyyy HH:mm format

Found this regular expression that apparently I can use for custom validation

^(([0-2][1-9])|([1-3][0-1]))[\\.\\-\\/](([0][1-9])|([1][0-2]))[\\.\\-\\/](([2-3][0-9][0-9][0-9])) *(([0-9])|([0-1][0-9])|([2][0-3])):(([0-5][0-9]))$

If it does not, I will go with server side validation, instead of client-side.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
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 …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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.

763 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

6 Experts available now in Live!

Get 1:1 Help Now