Reputation: 1211
I am building an asp.net application. In that i have 2 date fields, from date and to date. I used the ajax calender extender to show the calender. i need the date in MM/dd/YYYY format and i got it. But the thing is,if I select 12 dec 2013 it appears as 12/12/2013 and if I select 1 dec 2012, then it shows 12/1/2013. So what my issue is i just want the month and date to be in 2 digits always.ie 1 dec 2012 is 12/01/2012.My code is as follows.
<asp:TextBox ID="txt_from" placeholder="MM/DD/YYYY" runat="server"
AutoPostBack="True" ontextchanged="txt_from_TextChanged"></asp:TextBox>
<asp:CalendarExtender ID="txt_from_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txt_from">
</asp:CalendarExtender>
Upvotes: 4
Views: 48620
Reputation: 16632
Globalization is important but not enough. You must add below line into ScriptManager tag.
EnableScriptLocalization="true" EnableScriptGlobalization="true"
Upvotes: 1
Reputation: 28403
You have missed Format attribute in CalendarExtender
<asp:TextBox ID="txt_from" placeholder="MM/DD/YYYY" runat="server"
AutoPostBack="True" ontextchanged="txt_from_TextChanged"></asp:TextBox>
<asp:CalendarExtender ID="txt_from_CalendarExtender" runat="server" Format="MM/dd/yyyy"
Enabled="True" TargetControlID="txt_from">
</asp:CalendarExtender>
Happy Coding
Upvotes: 13
Reputation: 973
You can use Format property of Calendar Control as like below...
Format="MM/dd/yyyy"
Upvotes: 2
Reputation: 17614
You should use your web.config file as follows
<globalization culture="en-GB"/>
I think the problem could be the culture problem. If you set it in your web.config file it should work.
Here is a msdn link about culture setting
Upvotes: 6