将 CalendarExtender 与 MaskedEditExtender 结合使用
我试图拥有一个与本页上的第三个文本框完全相同的文本框功能: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/MaskedEdit/MaskedEdit.aspx。我尝试将 CalendarExtender 控件与 MaskedEditExtender 一起使用,因为我不希望用户能够在框中输入除有效日期之外的任何内容。在我的 maskededitextender 上,我有一个掩码“99/99/9999”,但它似乎只在日期实际上是 8 位数字(例如 12/12/2000)时才起作用,而不是在日期是 7 或 6 位数字(例如 1/ 1/2000 或 1/14/2000)。当日期少于 8 位时,掩码就会出错。这是我的代码:
<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>
如果我能弄清楚如何将 CalendarExtender 的日期格式获取为 MM/DD/YYYY 而不仅仅是 M/D/YYYY 就可以修复它。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
日历控件有一个格式属性一个>。用它来设置
There is a Format property of Calendar Control. Use that to set to
它的语法如下:
Format="MM/dd/yyyy"
并根据需要进行更改,但必须确保月份为大写,否则它将返回我使用的零 -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 -