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

Disable dates

3 Answers 114 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Mattias
Top achievements
Rank 1
Mattias asked on 03 Feb 2009, 02:37 PM
Hi,
I need to disable the dates outside the current month of the current view.
For example February, then I want to disable 26-31 of January and 1-8 of Mars.
I'm trying with the dayrender method with no success.
protected void radCalendar_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e) 
        { 
            if (e.Day.Date < _calendarFirstDateOfMonth || e.Day.Date > _calendarLastDateOfMonth) 
            { 
                e.Cell.Style.Add(HtmlTextWriterStyle.Cursor, "default"); 
                e.Cell.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#ff0000"); 
                e.Day.IsSelectable = false
                e.Day.IsDisabled = true
            } 
            else 
            { 
                if (SelectedEvents != null
                { 
                    foreach (Swh.Ih7.Entities.Event ev in SelectedEvents) 
                    { 
                        if (e.Day.Date >= ev.StartDate.Date && e.Day.Date <= ev.EndDate.Date) 
                        { 
                            e.Cell.Style.Add(HtmlTextWriterStyle.FontWeight, "700"); 
                        } 
                    } 
                } 
            } 
        } 
(the red background is set so the if-statement is working)

With this code I can still click on all dates! :(
Is it because I have AutoPostBack=true?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Feb 2009, 12:12 PM
Hello Mattias,

You can try out the following code to disable dates of other months on a calendar.
cs:
 protected void RadCalendar1_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e) 
    { 
       if (e.Day.Date.Month != RadCalendar1.FocusedDate.Month) 
           { 
               RadCalendarDay calendarDay = new RadCalendarDay(); 
               calendarDay.Date = e.Day.Date; 
               calendarDay.IsSelectable = false
              
               RadCalendar1.SpecialDays.Add(calendarDay);    
           
          }        
    } 

Thanks
Princy.
0
Mattias
Top achievements
Rank 1
answered on 04 Feb 2009, 12:59 PM
Thank you Princy, works great!

Is it possible to change the cursor? Now it's showing a hand and that misleads the user!


0
Dimo
Telerik team
answered on 05 Feb 2009, 07:22 PM
Hi Mattias,

Yes, in the DayRender handler provided by Princy you can set:

e.Cell.CssClass = "MyDisabled";


and then add some CSS:

.MyDisabled,
.MyDisabled a
{
    cursor: default;
}


All the best,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Calendar
Asked by
Mattias
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mattias
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or