Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Tuesday, June 12, 2012

How to highlight Today's Date in ASP.NET AJAX Calender Extender

Here is a simple way to highlight Today's Date in ASP.NET AJAX Calender Extender using JavaScript.

Code for .aspx page:

<asp:TextBox ID="DateTextBox" runat="server"  />
<asp:Image ID="Image1" runat="server" ImageUrl="Calendar_scheduleHS.png" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="DateTextBox" PopupButtonID="Image1" OnClientShowing="CurrentDateShowing">
</ajaxToolkit:CalendarExtender>

Here's the JavaScript:

<script type="text/javascript">
function CurrentDateShowing(e)
{
      if (!e.get_selectedDate() || !e.get_element().value)

      e._selectedDate = (new Date()).getDateOnly();
}    
</script>

That's it !!!!

Now try to run the page (view page in browser) - Once you click on calender image button, you would see Today’s date is highlighted.

No comments:

Post a Comment