Events Calender Help... - General Discussions - General Discussions - Progress Community
 General Discussions

Events Calender Help...

  • Events Calender Help...
  • I am working with the new Sitefinity 4.0 for the first time and all is going well. Part of the project is an events calendar and I am having trouble connecting my Events I create to a RadControl Calendar. Are there any blogs, examples, or discussions on the subject in 4.0 before I go getting into the code? It kind of seemed like the two controls would play nice together in a strait forward way.

    I would like a calendar on the left with the events to show up and perhaps a detailed description of the events on the right using the Events control.

    Thanks for any help,

    Charles

  • The Intranet Starter Kit has events module....

    Have a look at it... It might give you some clues...
  • Hey Charles,

    I'm trying to perform a similar task with the Calendar in Sitefinity 4.0. Have you had any luck getting the calendar to interact with the events?

    Thanks,

    Jeff
  • Not really...
    I just formated the Event to look like a calender entry... I was looking for a little more detail to my question but did not get it so I just did what I could because I just don't have time right now to research it.. When I get this project done I will go back and search around... If I find something I will post it...
    Charles
  • Hey Charles,

    Would you mind posting a link to the calendar that you are using?

    Thanks,

    Jeff
  • 249479_Events.jpg
    Not using a calendart yet... i just formated the event widget to look like a calendar entry. I will go back later and hook in the calendar if I figure it out. <see pic>
    Charles
  • Hi charles and Jeffrey,

    That is a tough one. What I could suggest you is to use the RadScheduler for ASP.NET in a Month View mode and link it to the Events.

    Please see the code samples below for further reference in building your EventsCalendar widget as a user control.

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EventsCalendar.ascx.cs" Inherits="SitefinityWebApp.MyControls.EventsCalendar" %>
    <telerik:RadScheduler runat="server" ID="Scheduler1" SelectedView="MonthView">
    </telerik:RadScheduler>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using Telerik.Sitefinity.News.Model;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.GenericContent.Model;
     
    namespace SitefinityWebApp.MyControls
        public partial class EventsCalendar : System.Web.UI.UserControl
        
            protected void Page_Load(object sender, EventArgs e)
            
                var events = App.WorkWith().Events().Where(n => n.Status == ContentLifecycleStatus.Live).Get().ToList();
                Telerik.Sitefinity.Events.Model.Event ev;
                Scheduler1.DataSource = events;
                Scheduler1.DataKeyField = "Id";
                Scheduler1.DataSubjectField = "Title";
                Scheduler1.DataStartField="EventStart";
                Scheduler1.DataEndField="EventEnd";
                Scheduler1.DataBind();
            
        

    I hope this information helps. Please let me know if I can assist you any further with this service request. Thank you in advance.

    Greetings,
    Boyan Barnev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hi Boyan,

    This code is perfect! It solved my problem. I am now trying to figure out how to tie it to a details page. Any ideas?

    I'll post the full VB.net code for my control when I finish this little project.
  • Hi David Arnold,

    Do you mind sharing with me some more details on the exact use case scenario you want to implement, so that I can give you a more focused answer. Thanks in advance.

    Greetings,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hi Boyan,

    I submitted a ticket on this issue last night, but basically I have a few issues and one really bad work-around.

    I have a radscheduler and it shows me one event (not all of the events?) from SiteFinity. I need to be able to link each event to the details page for that event. I think it's called EventView page in SiteFinity. I have listed my code at the bottom of this post.

    My problems are:
    1. Only one event shows up, not all of them
    2. If an event start date changes, my link will break
    3. Cannot go to another month (gives databinding error)

    Here's my control:

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="CalendarView.ascx.vb" Inherits="Controls_CalendarView" %>
    <telerik:RadScheduler runat="server" ID="Scheduler1" SelectedView="MonthView"
        AllowDelete="false"
        AllowEdit="false"
        AllowInsert="false"
        ShowViewTabs="false"
        OnClientNavigationCommand="OnClientNavigationCommand">
        <AppointmentTemplate>
            <asp:HyperLink ID="hyp1" runat="server" Text='<%# Eval("Subject") %>' NavigateUrl='<%# getURL(Eval("Start"), Eval("Subject"))%>' />
        </AppointmentTemplate>
    </telerik:RadScheduler>
      
    <script language="javascript">
        function OnClientNavigationCommand(sender, eventArgs)
            // 7 = SwitchToDayView  
            if (eventArgs.get_command() == 7) eventArgs.set_cancel(true);
          
      
    </script>

    And my code behind:
    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Web
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports Telerik.Web.UI
    Imports Telerik.Sitefinity.News.Model
    Imports Telerik.Sitefinity
    Imports Telerik.Sitefinity.GenericContent.Model
      
      
    Partial Class Controls_CalendarView
        Inherits System.Web.UI.UserControl
      
        Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
      
            Dim events = App.WorkWith().Events().Where(Function(n) n.Status = ContentLifecycleStatus.Live).[Get]().ToList()
      
            '--- was in example code, but not used anywhere?
            Dim ev As Telerik.Sitefinity.Events.Model.Event
      
            Scheduler1.DataSource = events
            Scheduler1.DataKeyField = "Id"
            Scheduler1.DataSubjectField = "Title"
            Scheduler1.DataStartField = "EventStart"
            Scheduler1.DataEndField = "EventEnd"
            Scheduler1.DataBind()
      
        End Sub
      
      
        Public Function getURL(eventDate As Date, title As String) As String  
            Dim _URL As String
            _URL = "/" & Year(eventDate)
            If Month(eventDate).ToString.Length = 1 Then
                _URL += "/0" & Month(eventDate)
            Else
                _URL += "/" & Month(eventDate)
            End If  
            If Day(eventDate).ToString.Length = 1 Then
                _URL += "/0" & Day(eventDate)
            Else
                _URL += "/" & Day(eventDate)
            End If
            _URL += "/" & LCase(Replace(title, " ", "-"))
            Return "~/calendar-view/event-details/" & _URL
        End Function
      
    End Class

    Thank you for your help.
  • Hi David Arnold,

    Please check the provided code sample below, it should offer a solution to all of the listed problems.

    First, enclosing the RadScheduler in a RadAjaxPanel and declaring the DataKeyField , DataSubjectField , DataStartField , and DataEndField properties in the template should fix the DataBind error you are receiving when you do a postback (for instance when switching to another date/view/month etc.)

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RadScheduler.ascx.cs" Inherits="SitefinityWebApp.Controls.RadScheduler" %>
    <telerik:RadAjaxPanel runat="server">
    <telerik:RadScheduler runat="server" ID="Scheduler1"
                            DataKeyField = "Id"
                            DataSubjectField = "Title"
                            DataStartField = "EventStart"
                            DataEndField = "EventEnd"
                            OnAppointmentCreated="Scheduler1_AppointmentCreated">
        <AppointmentTemplate>
            <asp:HyperLink id="eventDetailsLink" runat="server" />
        </AppointmentTemplate>
    </telerik:RadScheduler>
    </telerik:RadAjaxPanel>
    and in the code-behind please inspect the way links to the event items are constructed - composing of the Event item default URL and a page which contains an Events widget, so that the event can be displayed there. You should set the property SinglePage from the widget settings in the UI, to a page which contains an Events widget  :
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.GenericContent.Model;
    using Telerik.Sitefinity.Modules.Events;
    using Telerik.Sitefinity.Events.Model;
     
    namespace SitefinityWebApp.Controls
        public partial class RadScheduler : System.Web.UI.UserControl
        
            protected void Page_Load(object sender, EventArgs e)
            
                Scheduler1.DataSource = GetSourceItems();               
            
     
            protected virtual IList<Event> GetSourceItems()
            
                var list = new List<Event>();
                list = App.WorkWith().Events().Where(c => c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).Get().ToList();
                return list;
            
            public string SinglePage
            
                get;
                set;
     
            
     
     
            public void Scheduler1_AppointmentCreated(object sender, Telerik.Web.UI.AppointmentCreatedEventArgs e)
            
                var EManager = EventsManager.GetManager();
                var c = (HyperLink)e.Container.FindControl("eventDetailsLink");
                var data = EManager.GetEvent(new Guid(e.Appointment.ID.ToString()));
                c.Text = data.Title;
                c.NavigateUrl = SinglePage + data.Urls.Where(u => u.RedirectToDefault == false).SingleOrDefault().Url;
            
     
                   
        
     
     
             
     
            
     
            
    I hope you find this information useful, if you need any further assistance, please let us know.

    Kind regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hi Boyan,

    Thanks so much for pointing me in the right direction! I had a few issues with your code. I converted it to VB.net and wanted to post my code for other users:

    User control:

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="CalendarView.ascx.vb" Inherits="Controls_CalendarView" %>
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
     
        <telerik:RadScheduler runat="server" ID="Scheduler1" SelectedView="MonthView"
            AllowDelete="false"
            AllowEdit="false"
            AllowInsert="false"
            ShowViewTabs="false"
            DataKeyField = "Id"
            DataSubjectField = "Title"
            DataStartField = "EventStart"
            DataEndField = "EventEnd"
            OnAppointmentCreated="Scheduler1_AppointmentCreated"
            OnClientNavigationCommand="OnClientNavigationCommand"
            >
            <AppointmentTemplate>
                <asp:HyperLink ID="eventDetailsLink" runat="server" />
            </AppointmentTemplate>
        </telerik:RadScheduler>
     
    </telerik:RadAjaxPanel>
     
     
    <script language="javascript">
        function OnClientNavigationCommand(sender, eventArgs)
            // 7 = SwitchToDayView 
            if (eventArgs.get_command() == 7) eventArgs.set_cancel(true);
         
     
    </script>

    Code behind:
    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Web
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports Telerik.Sitefinity
    Imports Telerik.Sitefinity.GenericContent.Model
    Imports Telerik.Sitefinity.Modules.Events
    Imports Telerik.Sitefinity.Events.Model
     
    Partial Class Controls_CalendarView
        Inherits System.Web.UI.UserControl
     
        Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
     
            Scheduler1.DataSource = GetSourceItems()
     
        End Sub
     
     
        Protected Overridable Function GetSourceItems() As IList(Of [Event])
     
            Dim list = New List(Of [Event])()
            list = App.WorkWith().Events().Where(Function(c) c.Status = Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).[Get]().ToList()
            Return list
     
        End Function
     
        Public Property SinglePage() As String
            Get
                Return m_SinglePage
            End Get
            Set(value As String)
                m_SinglePage = Value
            End Set
        End Property
        Private m_SinglePage As String = "~/calendar-view/events-detail/"
     
        Public Sub Scheduler1_AppointmentCreated(sender As Object, e As Telerik.Web.UI.AppointmentCreatedEventArgs)
     
            Dim EManager = EventsManager.GetManager()
            Dim c = DirectCast(e.Container.FindControl("eventDetailsLink"), HyperLink)
            Dim data = EManager.GetEvent(New Guid(e.Appointment.ID.ToString()))
            c.Text = data.Title
            c.NavigateUrl = SinglePage + data.Urls.Where(Function(u) u.RedirectToDefault = False).FirstOrDefault().Url
     
        End Sub
    End Class


  • What property will allow it to open in Month tab?
    in otherwords, I want to see the Month view when I come to the page.

    THanks
  • Hello Nana,

    If you declare the SelectedView property to be equal to MonthView, this should ensure that RadScheduler will load initially in a month view mode. For more information on setting different view modes, please check this article from our documentation.

    Greetings,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items