New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

How to limit the navigation to present and future periods only

HOW-TO

Limit the navigation in RadScheduler to present and future periods only. In Week/Month/Timeline View the first valid period will be the one containing the Today's Date.

DESCRIPTION

RadScheduler's interface allows the user to navigate to any date either through its embedded Calendar or the rest of the navigational controls - the Previous, Next and Today buttons.

Sometimes, you may want to limit the user from navigating to periods which are in the past.

SOLUTION

Handle the NavigationCommand event of RadScheduler and verify if the user tries to navigate to a past period. If so, just cancel the event. Additionally, you could set the selected Date to be Today in case the user navigates through the Calendar to a past Date. Below is the code for the NavigationCommand event handler.

C#
protected void RadScheduler1_NavigationCommand(object sender, SchedulerNavigationCommandEventArgs e) 
{ 
    if (e.Command == SchedulerNavigationCommand.NavigateToSelectedDate) 
    { 
        if (e.SelectedDate < DateTime.Today) 
        { 
            e.Cancel = true; 
 
            //Uncomment if you want to navigate to the first available range. 
            //this.RadScheduler1.SelectedDate = DateTime.Today; 
        } 
    } 
    else 
    { 
        if ((e.Command == SchedulerNavigationCommand.DisplayPreviousAppointmentSegment) || 
            (e.Command == SchedulerNavigationCommand.NavigateToPreviousPeriod)) 
        { 
            if (this.RadScheduler1.SelectedView == SchedulerViewType.DayView) 
            { 
                if (this.RadScheduler1.SelectedDate == DateTime.Today) 
                { 
                    e.Cancel = true; 
                } 
            } 
            else if (this.RadScheduler1.SelectedView == SchedulerViewType.WeekView) 
            { 
                if (this.RadScheduler1.SelectedDate.AddDays(-7) < DateTime.Today) 
                { 
                    e.Cancel = true; 
                } 
            } 
            else if (this.RadScheduler1.SelectedView == SchedulerViewType.MonthView) 
            { 
                if (this.RadScheduler1.SelectedDate.AddMonths(-1) < DateTime.Today) 
                { 
                    e.Cancel = true; 
                } 
            } 
            else if (this.RadScheduler1.SelectedView == SchedulerViewType.TimelineView) 
            { 
                if (this.RadScheduler1.SelectedDate.AddDays(-1) < DateTime.Today) 
                { 
                    e.Cancel = true; 
                } 
            } 
        } 
    } 
} 
In this article
HOW-TODESCRIPTIONSOLUTION
Not finding the help you need?
Contact Support