在asp.net中使用MaskedEditExtender显示文本框当前日期时间 [英] Display Current Date Time in TextBox using MaskedEditExtender in asp.net
问题描述
我尝试显示txtDateTime当前日期时间
如何使用asp.net Maked编辑扩展的Ajax工具包的文本框中显示当前日期时间或自定义日期时间
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背后
推荐答案
您不要有写code在 txtDateTime.Text
,因为你正在使用AJAX控件。
You dont have to write code in txtDateTime.Text
since you are using ajax control.
您已设置的TargetControlID =txtDateTime
因此将automaticali采取在文本框中的日期。
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);
根据格式要设置日期,您可以编辑的String.Format。
Depending on format you want to set date, you can edit String.Format.
这篇关于在asp.net中使用MaskedEditExtender显示文本框当前日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!