CalendarExtender show only years

Here’s a working example. The code is self-explanatory.

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<script type="text/javascript" language="javascript">
function onCalendarShown() {
   var cal = $find("calendar1");
   cal._switchMode("years", true); 
   if (cal._yearsBody) {
      for (var i = 0; i < cal._yearsBody.rows.length; i++) {
         var row = cal._yearsBody.rows[i];
         for (var j = 0; j < row.cells.length; j++) {
             Sys.UI.DomEvent.addHandler(row.cells[j].firstChild, "click", call);
         }
        }
      }
   }

function onCalendarHidden() {
  var cal = $find("calendar1");
  if (cal._yearsBody) {
     for (var i = 0; i < cal._yearsBody.rows.length; i++) {
        var row = cal._yearsBody.rows[i];
        for (var j = 0; j < row.cells.length; j++) {
           Sys.UI.DomEvent.removeHandler(row.cells[j].firstChild, "click", call);
        }
     }
    }
}

function call(eventElement) {
   var target = eventElement.target;
   switch (target.mode) {
       case "year":
        var cal = $find("calendar1");
       cal.set_selectedDate(target.date);
       cal._blur.post(true);
       cal.raiseDateSelectionChanged(); break;
  }
}
</script>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" OnClientHidden="onCalendarHidden"  
 OnClientShown="onCalendarShown" Format="yyyy" BehaviorID="calendar1"  TargetControlID="TextBox1">
</ajaxToolkit:CalendarExtender>
</div>
</form>

Advertisements
This entry was posted in AJAXToolKit. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s