This is a migrated thread and some comments may be shown as answers.

Prevent user from navigate to PreviousPeriod

2 Answers 40 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Stargazer
Top achievements
Rank 2
Stargazer asked on 16 Sep 2013, 11:29 AM
Hello!

I have a requirement on my application that states no user can navigate to a date that falls within a specified interval (in this case a year, starting in September, for instance).

I manage to do this using pre-render event and setting the popup calendar min and max date properties. Using the popup works beautifully.

Now I need same functionality on the navigation buttons. I tried using NavigationCommand event, but when the command is NavigateToNextPeriodo or NavigateToPrevious period I can not do this, since I do not have a suitable date to compare with my interval, so I can decide to cancel or not the command. Like so:

if (e.Command == SchedulerNavigationCommand.NavigateToNextPeriod ||
    e.Command == SchedulerNavigationCommand.NavigateToPreviousPeriod ||
    e.Command == SchedulerNavigationCommand.NavigateToSelectedDate ||
    e.Command == SchedulerNavigationCommand.SwitchToSelectedDay)
{
    using (ServicoAnosLectivos servico = new ServicoAnosLectivos())
    {
        DateTime[] datas = servico.GetDatasAnoLectivo(ServicoTabelasBaseSistema.GetAnoLectivoActual(true));
        if (e.SelectedDate < datas[0] ||
            e.SelectedDate > datas[1])
        {
            e.Cancel = true;
        }
    }
}


Has anyone been on this kind of a picle? Is there any ideas on how to achieve this?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 19 Sep 2013, 12:29 PM
Hi,

 
Here is the code that should work for you for Day and WeekView for example:

protected void RadScheduler1_NavigationCommand(object sender, SchedulerNavigationCommandEventArgs e)
   {
       DateTime[] datas = { new DateTime(2013, 9, 8), new DateTime(2013, 9, 1) };
       RadScheduler scheduler=(RadScheduler)sender;
       if (e.Command == SchedulerNavigationCommand.NavigateToSelectedDate ||
                e.Command == SchedulerNavigationCommand.SwitchToSelectedDay)
       {
          
 
               if (e.SelectedDate < datas[0] &&
                   e.SelectedDate > datas[1])
               {
                   e.Cancel = true;
               }
            
       }
       else if (e.Command == SchedulerNavigationCommand.NavigateToNextPeriod)
       {
           if (scheduler.SelectedView==SchedulerViewType.DayView)
           {
               if (scheduler.SelectedDate.AddDays(1)< datas[0] &&
                   scheduler.SelectedDate.AddDays(1) > datas[1])
               {
                     e.Cancel = true;
               }
           }
           if (scheduler.SelectedView == SchedulerViewType.WeekView)
           {
               if (scheduler.SelectedDate.AddDays(7) < datas[0] &&
                   scheduler.SelectedDate.AddDays(7) > datas[1])
               {
                   e.Cancel = true;
               }
           }
       }
       else if (e.Command == SchedulerNavigationCommand.NavigateToPreviousPeriod)
       {
           if (scheduler.SelectedView == SchedulerViewType.DayView)
           {
               if (scheduler.SelectedDate.AddDays(-1) < datas[0] &&
                   scheduler.SelectedDate.AddDays(-1) > datas[1])
               {
                   e.Cancel = true;
               }
           }
           if (scheduler.SelectedView == SchedulerViewType.WeekView)
           {
               if (scheduler.SelectedDate.AddDays(-7) < datas[0] &&
                   scheduler.SelectedDate.AddDays(-7) > datas[1])
               {
                   e.Cancel = true;
               }
           }
       }
   }

Hope this will be helpful.

Regards,
Plamen
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Stargazer
Top achievements
Rank 2
answered on 19 Sep 2013, 04:08 PM
Hi Plament,

That did the trick. Just had to tweak the conditions and it was all set. 

Thanks!
Tags
Scheduler
Asked by
Stargazer
Top achievements
Rank 2
Answers by
Plamen
Telerik team
Stargazer
Top achievements
Rank 2
Share this question
or