ASP.NET - MaskedEditExtender problem with time

Asked By mostafa hamdy on 08-May-12 08:28 AM
Hello all
I have some web site in 4.0 contains some web page have some text boxs to display the date and time from data base , some text box I have set a MaskedEditExtender  to just allow the user to enter the valid time in 24h format
but when I have some date time like 04/05/2012 12:30 PM comes from database and I try to set it to the text box which assigne to the time I found that the time displaye like the following 24:30  really it makes me made, ,y html code
like the following:

<asp:TextBox ID="txtEditStartTime" runat="server" __designer:wfdid="w22" CssClass="StylText"

Width="50px" ></asp:TextBox>

<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender10" runat="server" TargetControlID="txtEditStartTime"

Mask="99:99" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus" UserTimeFormat="TwentyFourHour"

OnInvalidCssClass="MaskedEditError" MaskType="Time" DisplayMoney="Left" AcceptNegative="Left"

ErrorTooltipEnabled="True" />

and the enter code with in the cs file like the following:
ActionManager act = new ActionManager();

txtEditStartTime.Text = act.ActionStartDate.Value.ToShortTimeString();
and the value for the act.ActionStartDate from DB was  04/05/2012 12:30 PM  please if any body get what I mean and can help me please send me or tell me about some URL may help me to solve this issue

Somesh Yadav replied to mostafa hamdy on 09-May-12 02:24 AM
AutoFormatTime : function()


      if (this._AutoCompleteValue != "" )


        Mcur = this._AutoCompleteValue.substring(3,2); <---

        // replace to  this._AutoCompleteValue.substring(3,5)


    if (this._maskvalid == "99" + this.get_CultureTimePlaceholder()…


        if (this._AutoCompleteValue != "" )


          Scur = this._AutoCompleteValue.substring(5); <-----

        // replace to  this._AutoCompleteValue.substring(6);



Go through this link:

its similar to urs:

Vikram Singh Saini replied to mostafa hamdy on 09-May-12 07:17 AM
Try this way:

txtEditStartTime.Text = String.Format("{0:t}", act.ActionStartDate.Value.ToShortTimeString());

[)ia6l0 iii replied to mostafa hamdy on 09-May-12 10:10 AM
I see that your mask is a four digit mask (99:99), so it would be wise to custom format your time, and assign it to your textbox. 'tt' should show AM/PM.
txtEditStartTime.Text = String.Format("{0:hh:mm tt}",act.ActionStartDate.Value);

And also, you need to set "AcceptAMPM" property to "true" in the markup. And remove the "UserTimeFormat="TwentyFourHour" property.

<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender10" runat="server" TargetControlID="txtEditStartTime"
Mask="99:99" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus" 
OnInvalidCssClass="MaskedEditError" MaskType="Time" DisplayMoney="Left" AcceptNegative="Left" AcceptAMPM="true" ErrorTooltipEnabled="True" />

Hope that helps.