Vaguely related to what I'm working on now... a couple of suggestions that might help:
- I also do this just after doing "Thread.CurrentThread.CurrentCulture = ..."
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
I personnally build my CalendarExtender dynamically, but the important line is the Format:
ce = new CalendarExtender();
ce.ID = "CalExtender";
ce.Format = ShortDatePatternDoubleDigit;
and elsewhere I've got this static method:
public static string ShortDatePatternDoubleDigit
{
get
{
string shortDatePattern = Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortDatePattern;
if (!shortDatePattern.Contains("MM"))
shortDatePattern = shortDatePattern.Replace("M", "MM");
if (!shortDatePattern.Contains("dd"))
shortDatePattern = shortDatePattern.Replace("d", "dd");
if (!shortDatePattern.Contains("yyyy"))
shortDatePattern = shortDatePattern.Replace("yy", "yyyy");
return shortDatePattern;
}
}
as we have clients in the US and in the UK, the date must work in either mm/dd/yyyy or dd/mm/yyyy (and we use the masked edit extender hence the use of two digits for days and months).
On the client side of things, in javascript I can access the format string like this (getter), but I don't know if it can be set, I've not tried. It might help you in your "no postback" scenario:
var dateBox = $get('xxxx_DatePicker_TextBox');
var dateFormat = dateBox.CalendarBehavior._format; //this contains dd/MM/yyyy for example
Note that you might have to change this format again, for example, I'm using the jQuery UI datepicker, and MM is interpreted as Month Full Name, whereas in C# MM is a two-digit month. Worse, yyyy in C# is four-digit year, but for jQuery datepicker, yy is the four-digit year, so yyyy would end up with 20152015. You could do a dirty:
_format.replace(/M/g, "m").replace(/yy/g, "y")