I am using AjaxControlToolkit for .Net 4.0
I am having a form with textbox that displays/accepts date and time in MM/DD/YYYY HH:MM format i.e. US date format with 24 hour time format.
I have used TextBox with MaskedEditExtender and the MaskedEditValidator. Please look at the following code -
<p>
First Date Time :
<asp:TextBox ID="txtDateTime1" runat="server"></asp:TextBox>
<asp:MaskedEditExtender ID="mskDateTime1" runat="server"
Mask="99/99/9999 99:99" MaskType="DateTime" TargetControlID="txtDateTime1"
UserTimeFormat="TwentyFourHour">
</asp:MaskedEditExtender>
<asp:MaskedEditValidator ID="mskValDateTime1" runat="server"
ControlExtender="mskDateTime1" ControlToValidate="txtDateTime1"
IsValidEmpty="False"></asp:MaskedEditValidator>
</p>
<p>
Second Date Time :
<asp:TextBox ID="txtDateTime2" runat="server"></asp:TextBox>
<asp:MaskedEditExtender ID="mskDateTime2" runat="server"
Mask="99/99/9999 99:99" MaskType="DateTime" TargetControlID="txtDateTime2"
UserTimeFormat="TwentyFourHour">
</asp:MaskedEditExtender>
<asp:MaskedEditValidator ID="mskValDateTime2" runat="server"
ControlExtender="mskDateTime2" ControlToValidate="txtDateTime2"
IsValidEmpty="False"></asp:MaskedEditValidator>
</p>
For showing the dates in above format i am using format in ToString() as given below -
protected void Page_Load(object sender, EventArgs e)
{
txtDateTime1.Text = DateTime.Now.ToString("MM/dd/yyyy HH:mm");
txtDateTime2.Text = DateTime.Now.ToString("MM/dd/yyyy HH:mm");
}
The date and time is displayed correctly but when the focus goes out of the textboxes the time changes.
I don't know why this happening.
Please look at the following snapshots -
A) Originally
B) Changed after focus out
Can anybody help me out solve this issue.
Do provide better ideas if any.
Thanks for sharing your wisdom.
Finally, i have reply my own question as not received any replies from developers. I found it is actually an issue with MaskEditExtender. You can check this discussion.