Using a CalendarExtender with a MaskedEditExtender

2019-05-30 18:30发布

I'm trying to have a textbox function exactly like the third textbox down on this page: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/MaskedEdit/MaskedEdit.aspx. I'm trying to use a CalendarExtender control with a MaskedEditExtender, because I don't want the user to be able to enter anything except a valid date into the box. On my maskededitextender I have a mask of "99/99/9999" but it seems to only work when the date is actually 8 digits (e.g. 12/12/2000) and not when the date is 7 or 6 digits (e.g. 1/1/2000 or 1/14/2000). The mask screws up when the date is less than 8 digits. Here is my code:

<asp:TextBox runat="server" ID="txtDateAvailable" Width="150px" maxlength="50"></asp:TextBox>
<asp:CalendarExtender ID="calDateAvailable" runat="server" TargetControlID="txtDateAvailable" format="d" PopupPosition="Right"></asp:CalendarExtender>
<asp:MaskedEditExtender ID="mskDateAvailable" runat="server" targetcontrolid="txtDateAvailable" Mask="99/99/9999" clearmaskonlostfocus="false" MaskType="None"></asp:MaskedEditExtender>

If I could figure out how to get the date format of the CalendarExtender to MM/DD/YYYY instead of just M/D/YYYY that would fix it.

2条回答
forever°为你锁心
2楼-- · 2019-05-30 18:37

There is a Format property of Calendar Control. Use that to set to

Format="MM/dd/yyyy"
查看更多
叼着烟拽天下
3楼-- · 2019-05-30 18:53

The syntax for it is as follows: Format="MM/dd/yyyy" and change it around as you wish, but you must ensure that the month is in uppercase otherwise it will return zeros i used -

<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1" 
    PopupButtonID="ImageButton1" Format="dd/MM/yy">
查看更多
登录 后发表回答