views:

132

answers:

2

I am using a Masked Editor which is great and simple to use, but I was wondering. Is there a way to bind the time to a textbox that has a masked editor and cause the AM or PM to show up?

I know if you type an A or P AM and PM will show up, but how to you get it to appear to a bound textbox of time?

<asp:TextBox ID="txttime" runat="server" Width="90"></asp:TextBox>
                         <ajaxToolkit:MaskedEditExtender ID = "MaskedEditExtender1" AcceptAMPM="true"  ClearTextOnInvalid="true" ClearMaskOnLostFocus="false" runat="server" TargetControlID="txttime"
                         Mask="99:99" MaskType="Time"></ajaxToolkit:MaskedEditExtender>
                         <ajaxToolkit:MaskedEditValidator ID = "MEV"  ControlToValidate="txttime" runat="server" ControlExtender="MaskedEditExtender1" IsValidEmpty="false"></ajaxToolkit:MaskedEditValidator>

Here is the code that binds to the textbox. All i see is the time without AM or PM

DateTime datetime = Convert.ToDateTime(DataBinder.Eval(FormView1.DataItem, "Date"));   
txttime.Text = String.Format("{0:t}", datetime);
+2  A: 

Change

MaskType="Number"

To

MaskType="DateTime"

And include the following parameter:

AcceptAMPM="true"

So it would now be:

<asp:TextBox ID="txttime" runat="server" Width="90"></asp:TextBox>
                         <ajaxToolkit:MaskedEditExtender ID = "MaskedEditExtender1" AcceptAMPM="true"  ClearTextOnInvalid="true" ClearMaskOnLostFocus="false" runat="server" TargetControlID="txttime"
                         Mask="99:99" MaskType="DateTime" AcceptAMPM="true"></ajaxToolkit:MaskedEditExtender>
                         <ajaxToolkit:MaskedEditValidator ID = "MEV"  ControlToValidate="txttime" runat="server" ControlExtender="MaskedEditExtender1" IsValidEmpty="false"></ajaxToolkit:MaskedEditValidator>
Anthony M. Powers
I had Masktype = "Time". That works. Masktype = "Datetime" doesn't work. I also already have AMPM = "true"
Eric
Oh wow... Let me get some coffee!
Anthony M. Powers
haha. Thanks for your help anthony. +1.
Eric
A: 

ClearMaskOnLostFocus must be set to true. That was the issue. Thanks for the help.

ClearMaskOnLostFocus="true"

Here's where i found the answer

Click here

Eric
Ahhh..Well, best of luck.
Anthony M. Powers