C# 在asp.net中使用MaskedEditExtender在文本框中显示当前日期和时间
我尝试在txtDateTime中显示当前日期时间 如何使用asp.net中的Maked Edit Extender Ajax工具包在文本框中显示当前日期时间或自定义日期时间C# 在asp.net中使用MaskedEditExtender在文本框中显示当前日期和时间,c#,asp.net,date,datetime,asp.net-ajax,C#,Asp.net,Date,Datetime,Asp.net Ajax,我尝试在txtDateTime中显示当前日期时间 如何使用asp.net中的Maked Edit Extender Ajax工具包在文本框中显示当前日期时间或自定义日期时间 <asp:TextBox runat="server" ID="txtDateTime" ValidationGroup="ModalPopup"></asp:TextBox> <asp:CalendarEx
<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();
}
受保护的无效页面加载(对象发送方、事件参数e)
{
//txtDateTime.Text=DateTime.Now.ToString(“dd/MM/yyyyy H:MM”);
//txtDateTime.Text=DateTime.Now.ToString(“dd/MM/yyyy HH:MM”);
txtDateTime.Text=DateTime.Now.ToString();
}
代码隐藏您不必在
txtDateTime.Text
中编写代码,因为您使用的是ajax控件
您已经设置了TargetControlID=“txtDateTime”
,因此它将自动在该文本框中获取日期
如果要将其纳入屏蔽编辑扩展器,则:
txtDateTime.Text = String.Format("{0:t}", Now);
根据要设置日期的格式,可以编辑String.format。以何种格式显示日期时间。。??