Karan's Blog

Just Microsoft .Net

Calendar Extender Today’s Date

The following is a simple code to show how to set/highlight the selected date in a Calendar Extender as Today’s Date. I am using JavaScript to set the Calendar’s date. Here is the code:

Aspx:

   1: <asp:ToolkitScriptManager ID="toolKitScriptManger" runat="server" />
   2: <asp:TextBox  ID="txtCalender" runat="server" />  
   3: <asp:ImageButton ID = "imgCalender"  runat="server" ImageUrl="~/calendar.gif"/>
   4: <asp:CalendarExtender  ID="calenderExtender" runat="server"  CssClass="cal_theme" TargetControlID="txtCalender"  
   5:         PopupButtonID="imgCalender" OnClientShowing="CurrentDateShowing"/>   

In the above code I am calling Javascript function CurrentDateShowing on the CalendarExtender which set’s Today’s Date.

Here is the Javascript and a css class which I use on the Calendar Extender.

Css:

   1: .cal_theme .ajax__calendar_active    
   2:   {      
   3:       color: Red;       
   4:       font-weight: bold;       
   5:       background-color: #ffffff;  
   6:   } 

 

JavaScript:

   1: <script type="text/javascript">
   2:    function CurrentDateShowing(e) 
   3:    {
   4:        if (!e.get_selectedDate() || !e.get_element().value)
   5:            e._selectedDate = (new Date()).getDateOnly();
   6:    }     
   7:    </script>

On using the above code when the Calendar pops up on the Image Button Click you would see Today’s date is highlighted in Red.

Posted: Sep 20 2010, 11:16 PM by karan@dotnet | with 5 comment(s) |
Filed under: , ,

Comments

AR said:

nice one work on all browsers

# October 14, 2010 7:27 AM

Calendar Extender Highlight Current Day in C# .Net « Fraction of the Blogosphere said:

Pingback from  Calendar Extender Highlight Current Day in C# .Net &laquo; Fraction of the Blogosphere

# May 24, 2011 11:49 AM

Abhijeet said:

great solution its helpfull a lot

# January 19, 2012 1:03 AM

Sanjit Kumar said:

its really helpful for me. Its working fine in my appln. thanks a lot

Regards

Sanjit

# April 28, 2012 12:20 PM

David Rocke said:

Makes entering today's date a lot easier.

Many Thanks.

# May 21, 2012 9:22 AM