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

Disable dates in RadDatePicker

5 Answers 1330 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Saqib
Top achievements
Rank 1
Saqib asked on 21 Mar 2014, 10:39 PM
How to disable days in RadDatePicker?
If I google to find, everyone is referring to article which doesn't work in vs2013.
http://www.telerik.com/support/code-library/disabling-calendar-days

I also tried to do with following functions but it only disables like 10 total weekends.  It doesn't disable any previous months weekends. Any suggestions!
    Protected Sub Calendar_OnDayRender(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.DayRenderEventArgs)
        If (e.Day.Date.DayOfWeek = DayOfWeek.Saturday Or e.Day.Date.DayOfWeek = DayOfWeek.Sunday) Then     
            ' disable the selection for the specific day
            Dim calendarDay As RadCalendarDay = New RadCalendarDay
            calendarDay.Date = e.Day.Date
            calendarDay.IsSelectable = False
            calendarDay.IsDisabled = True
            'calendarDay.ItemStyle.CssClass = otherMonthCssClass
            calendarDay.ItemStyle.BackColor = Color.CadetBlue
            RadDatePicker1.Calendar.SpecialDays.Add(calendarDay)
        End If    End Sub

5 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 26 Mar 2014, 12:05 PM
Hello Saqib,

If you would like to disable days in RadDatePicker I would recommend checking this code library. It illustrates how to achieve such scenario. Note that you need to handle both client-side OnDayRender and server-side DayRender events.

Try using the approach demonstrated in the code library and you should be able to achieve the functionality you are looking for.

Regards,
Viktor Tachev
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Saqib
Top achievements
Rank 1
answered on 31 Mar 2014, 07:37 PM
I tried to work with code library but when I try to run the project, I get "Object Null reference error".
Somehow this control is not working right in VS 2013.
0
Viktor Tachev
Telerik team
answered on 01 Apr 2014, 02:04 PM
Hello Saqib,

I tested the code-library and it seems to work as expected with Visual Studio 2013. Would you elaborate more on your setup and how to reproduce the error? Is the error replicated in all browsers?

In case you would need only the weekends to be disabled you could use the EnableWeekends property to achieve the functionality with no additional code.

<telerik:RadDatePicker ID="RadDatePicker1" runat="server" >
    <Calendar EnableWeekends="false">
    </Calendar>
</telerik:RadDatePicker>

Another approach you could use is to add the dates that should be disabled as SpecialDays. For example the following code will disable all Tuesdays.

<telerik:RadDatePicker ID="RadDatePicker1" runat="server">
    <Calendar runat="server" ID="Calendar1">
        <SpecialDays>
            <telerik:RadCalendarDay Date="2014.04.01" Repeatable="Week" IsSelectable="false" IsDisabled="true"></telerik:RadCalendarDay>
        </SpecialDays>
    </Calendar>
</telerik:RadDatePicker>


Regards,
Viktor Tachev
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Saqib
Top achievements
Rank 1
answered on 01 Apr 2014, 04:42 PM
In my existing Telerik project VS2013, I added DLL/css/js files from this project. I then register the control in the aspx page and declared the control in the page. Now when I try to run the page, it fails in the page_load function at the end of it.
But if I comment this control, then the page loads successfully.
Also there are 2 links: Classic and Ajax.
I tried it with ajax.

Also the control doesn't have the appearance (when I ran the downloaded code in VS2008) as the normal RadCalendar control out of box in toolkit.
0
Viktor Tachev
Telerik team
answered on 04 Apr 2014, 07:32 AM
Hi Saqib,

Thank you for writing back.

I have prepared a runnable website project from the code library. Try opening it in Visual Studio as a WebSite and try out the page.

Regarding the appearance of the picker control. Please ensure that all Telerik assembly files that are added to your project have the same version. If the Telerik.Web.UI.dll and Telerik.Web.UI.Skins.dll are different versions the Skin for the RadDatePicker could be displayed in an unexpected way.

Would you also let me know if the other suggestions (using EnableWeekends property of SpecialDays) for achieving the functionality are working for you?

I am looking forward to your reply.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Calendar
Asked by
Saqib
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Saqib
Top achievements
Rank 1
Share this question
or