问题
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