我在aspnet中使用CalendarExtender和TextBox。
<asp:TextBox ID="txtDateTime" TextMode="DateTime" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server"
TargetControlID="txtDateTime" Format="G" Animated="True" PopupPosition="Right"
FirstDayOfWeek="Monday"></ajaxToolkit:CalendarExtender>
在Page_Load事件中,我将当前日期和时间设置为TextBox的值:
txtDateTime.Text = DateTime.Now.ToString();
然后,CalendarExtender无法正常工作。日历框架变为完全白色。你帮助我了,这里有什么问题?
答案 0 :(得分:0)
<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 = String.Format("{0:t}", Now);
}
下面的stackoverflow链接 Display Current Date Time in TextBox using MaskedEditExtender in asp.net
答案 1 :(得分:0)
您也需要使用MaskedExtender。
<asp:TextBox ID="TextBoxID" runat="server"/>
<ajaxToolkit:MaskedEditExtender ID="MaskData" runat="server" TargetControlID="TextBoxID" Mask="99/99/9999" MaskType="Date"/>
然后您可以使用calendarExtender
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Enabled="True" TargetControlID="TextBoxID" Format="dd/MM/yyyy"/>