How To: Customize Calendar Control to limit the users to select day on or after today

In this Sample code we will see how to customize calendar control to limit the user to select the day on or after today

Step 1: Drag Drop Calendar Control

<asp:Calendar id="Calendar1"  runat="server"></asp:Calendar>

Step 2: In code behind use the below code in DayRender Event

The DayRenderEventArgs object contains two properties that you can use to programmatically control the format of the date cell. The Cell property represents the cell being rendered, while the Day property represents the date to render in the cell.

Set the Day's IsSelectable property to true or false depending on the criteria. In this code sample we will limit user to select day on or after today.

VB.NET Code

Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender

e.Day.IsSelectable = e.Day.Date >= DateTime.Now

End Sub

C# Code

void OnDayRender (Object sender, DayRenderEventArgs e)

{

e.Day.IsSelectable = e.Day.Date >= DateTime.Now;

}

1 Comment

Comments have been disabled for this content.