2010-10-23 8 views
0

J'ai eu Ajax Calendar et je veux empêcher l'utilisateur de choisir la date (Aujourd'hui ou future date) J'ai eu le code de script Java mais Il quand je m'empêche de sélectionner la date plus tôt que (10-10-1990) .Plaes quelqu'un m'aider.Date du format dans le calendrier Ajax

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> 

Répondre

0

Vous ne devriez pas compter sur javascript pour valider votre entrée. Veuillez utiliser votre point de terminaison d'application pour cela. En outre, vous pouvez utiliser jQuery par exemple pour réaliser ce que vous voulez.

0

Que diriez-vous:

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

if(sender._selectedDate < today) {  
}