cultureInfo calendar DateTime problem

G

Guest

Hi all,

In a user control, the user can put the cultureinfo to his preference,
choosing between "nl-BE","fr-BE", and "en-US". this way all calendar and
datetime properties are set in the right structure.
In a webform I have two textboxes which are filled in by a CalendarPicker in
a Pop-up window, a StartDate and an EndDate.

Works fine.

But on Form.submit, the two textbox.Text are converted by this method
DateTime.ParseExact(TextBox.text, 'ddd,dd MMM yyyy', format)
where format is CurrentCulture.CultureInfo

This works fine if the user does not change his language preferences (and
thus the cultureInfo).

But he wants his application to work in english or french, he gets a
'Datetime is not valid' parser error

Anyone ?
 
K

Ken Cox [Microsoft MVP]

You're getting the error because ParseExact is trying to deal with a
hardcoded date format that make no sense for some cultures. Imagine what
happens when the user enters 15 for the day but it is being used in the code
as the month value.

The whole page and its controls need to use the same culture info, including
the UI culture.

You might want to try it without ParseExact to see if the datetime will be
accepted for the selected culture.
 
G

Guest

the user cannot manually add the date to the textbox, it goes with a pop-up
window, a calendar tool and the value is formatted to the same string as the
one parseExact uses
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top