CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

How to disable past/previous dates in Calendar Control in ASP.Net?
Submitted By Satheesh Babu B
On 7/21/2010 8:07:13 AM
Tags: ASP.Net,CodeDigest  

How to disable past/previous dates in Calendar Control in ASP.Net?

 

There will be situations where we need to disable or make the past dates not selectable in Caledar control. This little code snippet will help you to do that using the DayRender event.

 

In DayRender event, we can set the e.Day.IsSelectable property to false which will render the day as non clickable. By default, every date in the calendar control will be displayed as link which enables to select the date. Setting the above said property will disable the link and will display the particular date as a text instead of link.
 
Refer the below code,
 
ASPX
<asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender"> </asp:Calendar>
 
CodeBehind
  protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
         if (e.Day.Date.CompareTo(DateTime.Today) < 0)
        {
            e.Day.IsSelectable = false;
        }
     }


The above code will disable the past/previous dates so that users will not be able to select those dates.
 
Happy Coding!!


 

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..