How to set current date in CalendarExtender

11.4k Views Asked by At

Requirement is simple.

How to set current date in CalendarExtender control.

<cal:CalendarExtender ID="calDate" runat="server" SelectedDate="2008-01-01" TargetControlID="txtDate" CssClass="CalendarExtender" Format="yyyy/MM/dd">

Here the selected date is 2008-01-01. I need to show current date instead of 2008-01-01

Appreciate your assistance

2

There are 2 best solutions below

5
On BEST ANSWER

You just need to assign it in codebehind, for example in Page_Load:

if(!IsPostBack)
   calDate.SelectedDate = DateTime.Today;
0
On

Another example using @Hutchonoid approach: example below illustrate how to correctly use ajaxcontrolTookKit CalendarExtender.

<ajaxControlToolKit:CalendarExtender runat="server"
           id="cal1"
           TargetControlID="txtDateFrom"
           CssClass="MyCalendar ajax__calendar ajax__calendar_hover"
           Format="dd/MM/yyyy"
           PopupButtonID="imgControl"
           PopupPosition="BottomRight"
           SelectedDate="<%# DateTime.Today %>"  >
           </ajaxControlToolKit:CalendarExtender>
           <asp:TextBox  Type="text" ID="txtDateFrom" runat="server"></asp:TextBox>
           <asp:ImageButton ID="imgControl" runat ="server"  ImageUrl 
           ="~/_icons/ajaxcalendar.png" />

Hope the above code snip-it helps or at least clarify the concept.