Display Current Date Time in TextBox using MaskedEditExtender in asp.net

无人久伴 提交于 2020-01-05 08:51:47

问题


I try to display current DateTime in txtDateTime How to display current datetime or custom date time in the textbox using Maked Edit Extender Ajax tool kit in asp.net

<asp:TextBox runat="server" ID="txtDateTime" ValidationGroup="ModalPopup"></asp:TextBox>
                                            <asp:CalendarExtender runat="server"
                                                TargetControlID="txtDateTime"
                                                PopupPosition="TopRight" 
                                                Format="dd/MM/yyyy HH:mm">
                                            </asp:CalendarExtender>
                                            <asp:MaskedEditExtender runat="server"
                                                ID="meeDateTime"
                                                TargetControlID="txtDateTime"
                                                Mask="99/99/9999 99:99"
                                                MaskType="DateTime"
                                                UserDateFormat= "DayMonthYear"
                                                UserTimeFormat="TwentyFourHour"
                                                CultureDateFormat="DMY"
                                                CultureDatePlaceholder="/"           CultureTimePlaceholder=":">
                                            </asp:MaskedEditExtender>

protected void Page_Load(object sender, EventArgs e)
        {
//txtDateTime.Text = DateTime.Now.ToString("dd/MM/yyyy H:mm);
//txtDateTime.Text = DateTime.Now.ToString("dd/MM/yyyy HH:mm);
txtDateTime.Text = DateTime.Now.ToString();
}

code Behind


回答1:


You dont have to write code in txtDateTime.Text since you are using ajax control.

You have set TargetControlID="txtDateTime" so it will automaticali take the date in that text box.

If you want to take it in masked Edit extender, then:

 txtDateTime.Text =   String.Format("{0:t}", Now);

Depending on format you want to set date, you can edit String.Format.



来源:https://stackoverflow.com/questions/18566184/display-current-date-time-in-textbox-using-maskededitextender-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!