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

Disabling dates on calendar without using javascript

5 Answers 91 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Katie
Top achievements
Rank 1
Katie asked on 05 Jul 2012, 07:34 PM
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

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Jul 2012, 07:28 AM
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.
0
Katie
Top achievements
Rank 1
answered on 09 Jul 2012, 10:34 AM
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.
0
Shinu
Top achievements
Rank 2
answered on 09 Jul 2012, 01:36 PM
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.
0
Katie
Top achievements
Rank 1
answered on 09 Jul 2012, 01:57 PM
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
0
Maria Ilieva
Telerik team
answered on 12 Jul 2012, 10:29 AM
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.
Tags
Calendar
Asked by
Katie
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Katie
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or