Software development stuff.

2007-12-17

Using both MaskedEditExtender and calendarextender

It's not easy to use the Ajax Toolkit controls like the example in here for editing a date. Well, at least not easy if you want it to be multicultural. I used the following: //Set the culture settings CultureInfo oCulture = CultureInfo.CurrentCulture; CalendarMaskExtender1.CultureName = oCulture.Name; CalendarExtender1.Format = oCulture.DateTimeFormat.ShortDatePattern; //CalendarMaskExtender expects something like "99/99/9999" CalendarMaskExtender1.Mask = CalendarExtender1.Format.Replace( oCulture.DateTimeFormat.DateSeparator, "/").Replace( "d", "9").Replace( "M", "9").Replace( "y", "9"); And don't forge tot set the <asp:ScriptManager EnableScriptGlobalization="true">

Argh, how do you set the format on this blogger.....aahh, just view source of this page if you need to check the code..

Etiquetas:

2 Comments:

Blogger Unknown said...

Hi thanks for the code, it really helped me out a lot. It isn't fully working though since some cultures use a format like this: d-M-yyyy (dutch format) to solve this I changed the code like this.

//Set the culture settings
CultureInfo oCulture = CultureInfo.CurrentCulture;
CalendarMaskExtender1.CultureName = oCulture.Name;
CalendarExtender1.Format = oCulture.DateTimeFormat.ShortDatePattern;
//CalendarMaskExtender expects something like "99/99/9999"
string Mask = CalendarExtender1.Format.Replace(oCulture.DateTimeFormat.DateSeparator, "/");
if (Mask.IndexOf("d") != Mask.LastIndexOf("d"))
{
Mask = Mask.Replace("d", "9");
}
else
{
Mask = Mask.Replace("d", "99");
}
if (Mask.IndexOf("M") != Mask.LastIndexOf("M"))
{
Mask = Mask.Replace("M", "9");
}
else
{
Mask = Mask.Replace("M", "99");
}
Mask = Mask.Replace("y", "9");
CalendarMaskExtender1.Mask = Mask;

this way it checks whether there are two d's or M's, and if not, replaces the single d or M with 99

09:51

 
Anonymous Anónimo said...

Muchas gracias. Es un código extraordinario.

04:08

 

Enviar um comentário

<< Home