Prevent user from navigate to PreviousPeriod

3 posts, 0 answers
  1. Stargazer
    Stargazer avatar
    73 posts
    Member since:
    Jan 2007

    Posted 16 Sep 2013 Link to this post

    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. Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 19 Sep 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Stargazer
    Stargazer avatar
    73 posts
    Member since:
    Jan 2007

    Posted 19 Sep 2013 Link to this post

    Hi Plament,

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

    Thanks!
Back to Top