Click here to Skip to main content
15,922,145 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
if (sender._selectedDate > new Date().getYear) {

                   alert(" You cannot select a date greater than current year!");
                   sender._selectedDate = new Date();
                   sender._textbox.set_Value(sender._selectedDate.format(sender._format))
               }

In above code i wanted to check year value entered by user with current year but am not able to extract year value from sender._selectedDate . Please suggest the solution..

The sender is calenderExtender control . Here is the code snippet..
XML
<ItemTemplate>
                                        <asp:TextBox ID="txtdeadline" contentEditable="False" runat="server"
                                Height="40px" Width="57px"></asp:TextBox>
                                        <asp:CalendarExtender ID="txtdeadline_CalendarExtender" runat="server"
                                Enabled="True" OnClientDateSelectionChanged="checkDate" TargetControlID="txtdeadline">
                                        </asp:CalendarExtender>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtdeadline"
                                ErrorMessage="*" SetFocusOnError="True" ValidationGroup="valgrp_func"></asp:RequiredFieldValidator>

                                    </ItemTemplate>
Posted
Updated 5-Feb-14 19:56pm
v2
Comments
Karthik_Mahalingam 6-Feb-14 1:52am    
what is sender ??
post full code..
Ni!E$H_WAGH 6-Feb-14 1:55am    
<itemtemplate>
<asp:TextBox ID="txtdeadline" contentEditable="False" runat="server"
Height="40px" Width="57px">
<asp:CalendarExtender ID="txtdeadline_CalendarExtender" runat="server"
Enabled="True" OnClientDateSelectionChanged="checkDate" TargetControlID="txtdeadline">

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtdeadline"
ErrorMessage="*" SetFocusOnError="True" ValidationGroup="valgrp_func">

Ni!E$H_WAGH 6-Feb-14 1:58am    
Dear KARTHIK I have improved the question ..
Karthik_Mahalingam 6-Feb-14 3:47am    
ok iwil check it.

You can Compare the two Date


DateTime dt1 =Convert.toDateTime(txtdeadline.text);
DateTime dt = DateTime.Now;

If(dt.Year=dt1.year)
{
------your logic goes here
}
 
Share this answer
 
Try this


JavaScript
var checkDate = function (sender, args) {

          var date = new Date(Date.parse(sender._selectedDate));
          var year = date.getFullYear();

          if (year > new Date().getFullYear()) {
              alert(" You cannot select a date greater than current year!");
 
Share this answer
 
Comments
Ni!E$H_WAGH 6-Feb-14 4:35am    
Thanks
Karthik_Mahalingam 6-Feb-14 4:42am    
welcome Ni!E$#4U:)
Siva Hyderabad 6-Feb-14 6:17am    
+5
Karthik_Mahalingam 6-Feb-14 8:02am    
Thanks Siva:)
Karthik_Mahalingam 25-Feb-14 1:26am    
Hi siva, i am back after 2 weeks vacation.
ya i am fine. how r u.
C#
<script type="text/javascript">
         function checkDate(sender, args) {
             var dt1 = new Date().getYear();
            var dt2 = sender._selectedDate.getYear();


            var t1 = new Date().getDay();
            var usrday = sender._selectedDate.getDay();

            var m1 = new Date().getMonth();
            var usrmonth = sender._selectedDate.getMonth();

             if (usrday < t1 || usrday < m1 || dt2 < dt1 ) {
                 alert("You cannot select a day earlier than today!");
                           }
             else  if (dt2 > dt1) {

                     alert(" You cannot select a date greater than current year!");(sender._format))
                 }
         }
    </script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900