Disabling dates on calendar without using javascript

6 posts, 0 answers
  1. Katie
    Katie avatar
    6 posts
    Member since:
    Jun 2012

    Posted 05 Jul 2012 Link to this post

    I have been following the instructions here to update my calendar and was wondering if there is a way of doing this without using javascipt?
    Ideally I would like to be able to set the disabled dates in the server code and not have to replicate it into javavscript. I have quite a few complicated calculations to do, and lookups in a databas to determine if a date should be disabled, and need to set this on the page load. The minimum and maximum dates also which I set on page load seem to be ignored once a user navigates to the next or previous month.
    Thanks
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Jul 2012 Link to this post

    Hi Katie,

    Here is the sample code that I tried based on your scenario which works as expected.

    C#:
    protected void Page_Load(object sender, EventArgs e)
     {
      RadCalendarDay calendarDay = new RadCalendarDay();
      DateTime dt = new DateTime(2012, 06, 20); // Date to disable 
      calendarDay.Date = dt.Date;
      calendarDay.IsDisabled = true;
      calendarDay.IsSelectable = false;
      RadCalendar1.SpecialDays.Add(calendarDay);
      DateTime start = new DateTime(2012, 05, 20);  // Minimum Date
      DateTime end = new DateTime(2012, 07, 20);    //// Maximum Date
      RadCalendar1.RangeMaxDate = end;
      RadCalendar1.RangeMinDate = start;
     }

    hope this helps.

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Katie
    Katie avatar
    6 posts
    Member since:
    Jun 2012

    Posted 09 Jul 2012 Link to this post

    Thank you for your reply, however this doesn't fix my problem, The issue I am having is that the disabled dates aren't always in the initial month displayed on the calendar, so as an example if I did this:

    protected void Page_Load(object sender, EventArgs e)
     {
      RadCalendarDay calendarDay = new RadCalendarDay();
      DateTime dt = new DateTime(2012, 06, 20); // Date to disable
      calendarDay.Date = dt.Date;
      calendarDay.IsDisabled = true;
      calendarDay.IsSelectable = false;
      RadCalendar1.SpecialDays.Add(calendarDay);
      RadCalendarDay calendarDay1 = new RadCalendarDay();
      DateTime dt1 = new DateTime(2012, 08, 20); // Date to disable
      calendarDay1.Date = dt1.Date;
      calendarDay1.IsDisabled = true;
      calendarDay1.IsSelectable = false;
      RadCalendar1.SpecialDays.Add(calendarDay1);
      DateTime start = new DateTime(2012, 05, 20);  // Minimum Date
      DateTime end = new DateTime(2012, 09, 20);    //// Maximum Date
      RadCalendar1.RangeMaxDate = end;
      RadCalendar1.RangeMinDate = start;
     }
    The disable dates don't persist when the user clciks to the next month.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 Jul 2012 Link to this post

    Hi Katie,

    Try  the following code to focus on the disabled date.

    C#:
    RadCalendarDay calendarDay = new RadCalendarDay();
    DateTime dt = new DateTime(2012, 06, 20); // Date to disable
    ...............................
    RadCalendar1.RangeMinDate = start;
    RadCalendar1.FocusedDate = dt;

    Hope this helps.

    Thanks,
    Shinu.
  6. Katie
    Katie avatar
    6 posts
    Member since:
    Jun 2012

    Posted 09 Jul 2012 Link to this post

    Hi Shinu,

    Thanks for your reply, however I don't want to focus on the disabled date, I need the calendar to focus on todays date and then when I add in the disabled dates for the following 6 months, I need them to persist through the user clicking through the months.
    At the moment it appears that as soon as the user clicks on the next month all disabled dates are wiped and so is the min and max date.

    Thanks

    Katie
  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 12 Jul 2012 Link to this post

    Hello Katie,
     
    Please note that in case you want to persists the disabled dates when navigating you should handle to both server and client side events as shown in the CodeLibrary you mentioned in your first post. Unfortunately this could not be achieved only on the server.

    Greetings,
    Maria Ilieva
    the Telerik team
    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 their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017