CODEDIGEST
Home Articles CodeDigest Tutorials FAQs
Home > CodeDigest >  
Technologies
 


How to disable a particular date of a month in ASP.Net Calendar Control?
Submitted By Satheesh Babu B
On 7/20/2010 8:49:48 AM
Tags: ASP.Net,CodeDigest  

How to disable a particular date of a month in ASP.Net Calendar Control?

 

At times, we may have a requirement to disable a particular date in Calendar control so that the users cannot select that date. This little code snippet will help you to do that using the DayRender event of Calendar control.

 

The CalendarDay object returned by DayRenderEventArgs.Day property has a property called IsSelectable which on setting false will render the date as a non clickable object in DayRender event. We can use this property and make a particular date as non selectable in Calendar control.

 

The below code does that,
 
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.ToShortDateString() == "7/27/2010")
        {
            e.Day.IsSelectable = false;
        }
     }
 
The above code will disable July 27, 2010 when rendering the Calendar control.

Happy Coding!!

 

Recent Codes
  • View All Codes..