views:

18

answers:

2

I had Ajax Calendar and I want to prevent user to choose date (Today or future date) I had java script code but It when I prevent me to select date earlier as (10-10-1990).Plaes any one help me.

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>
A: 

You should not rely on javascript to validate your input. Please user your application endpoint to do so. Furthermore, you may want to use jQuery for example to achieve the thing that you want.

Warden
A: 

How about:

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

if(sender._selectedDate < today) {    
}
Jakub Konecki