Tuesday, March 20, 2012

How to disable previous dates in Calendar control in ASP.NET


This is a simple code but many people got confused about this inbuilt feature in .NET Calendar control.

We will be using Calendar DayRender control to disable all the previous dates.

First we will add the Calendar control,

<asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender">

No we will see what you have to write under DayRender event,

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
            if (e.Day.Date < DateTime.Now.Date)
                e.Day.IsSelectable = false;
                e.Cell.ForeColor = System.Drawing.Color.Gray;


See the Calendar control after disabling the previous dates,



Isaiah Bett said...

It was a wonderfull code .It works for me

Anonymous said...

You have been very helpful. Thanks

Pavithra M said...

It is really a great work and the way in which u r sharing the knowledge is excellent.
Thanks for helping me to understand basic concepts. As a beginner in Dot Net programming your post help me a lot.Thanks for your informative article.
Dot Net Training in chennai | top10 dot net training institutes in chennai

Mithun Mithun said...

Given so much information in it. its very useful .perfect explanation about Dot net framework.Thanks for your valuable information. dot net training and placement in chennai | dot net training institute in velachery