在Ajax日历中格式化日期

时间:2010-10-23 08:40:52

标签: javascript asp.net-ajax

我有Ajax日历,我想阻止用户选择日期(今天或未来日期)我有java脚本代码但是当我阻止我选择日期时(10-10-1990).Plaes任何一个帮助我

的Javascript

<script type="text/javascript">
       function checkDate(sender,args)
{
 if (sender._selectedDate < new Date()) 
            {
                alert("You cannot select a day earlier than today!");
                sender._selectedDate = new Date(); 
                // set the date back to the current date
sender._textbox.set_Value(sender._selectedDate.format(sender._format))
            }
}
    </script>

ASPX

<table>
<tr>
    <td class="bod_d_reg_txt_p lm7"> Birth year : </td>
    <td colspan="3"><asp:TextBox ID="TXTBirthdate" runat="server" Width="150px" ReadOnly="True"></asp:TextBox>
        <label>
            <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TXTBirthdate"
                                                                            OnClientDateSelectionChanged="checkDate" PopupButtonID="Image1"> </cc1:CalendarExtender>
            <asp:Image ID="Image1" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png" />
        </label>
        <asp:CompareValidator ID="cmp" ControlToValidate="TXTBirthdate" runat="server" ErrorMessage="*"
                                                                        Operator="LessThanEqual" Type="Date" Display="Dynamic">*</asp:CompareValidator>
        <br />
        <span style="font-family: 'MS SystemEx'; color: #C0C0C0">(Click the image button to
        show the calendar to choose your date) </span></td>
</tr>
</table>

2 个答案:

答案 0 :(得分:0)

您不应该依赖javascript来验证您的输入。请使用您的应用程序端点来执行此操作。 此外,您可能希望使用jQuery来实现您想要的东西。

答案 1 :(得分:0)

怎么样:

var today = new Date();
today.setDate(today.getDate() - 1);

if(sender._selectedDate < today) {    
}