Disable Weekends in ASP.NET Calendar Control

While using the ASP.NET Calendar Control, a common requirement is to prevent the users from selecting any dates that fall on a weekend (Saturday & Sunday). Here’s how to do so by using the DayRender event of the ASP.NET Calendar control.

<asp:Calendar ID="wkDayCalendar" runat="server"
ondayrender="wkDayCalendar_DayRender" >


protected void wkDayCalendar_DayRender(object sender,
DayRenderEventArgs e)
e.Day.IsSelectable = !e.Day.IsWeekend;


Protected Sub wkDayCalendar_DayRender(ByVal sender As Object,
ByVal e As DayRenderEventArgs)
e.Day.IsSelectable = Not e.Day.IsWeekend
End Sub


As you can see, the user cannot select any dates from the weekend as it is not selectable any more.


Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

1 comment:

julie nelson said...

Thank you. Can't get any simpler than that for a solution.