Hello Plamen, Here is the aspx and cs. Hopefully you will be able to spot where I have gone wrong!
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CCalendar.ascx.cs" Inherits="CommsCalendar.CCalendar.CCalendar" %>
<%@ Register assembly="Telerik.Web.UI, Version=2014.1.403.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<
style
>
.rsHeader
{
z-index:50 !important;
}
</
style
>
<
telerik:RadScheduler
ID
=
"RadScheduler1"
runat
=
"server"
DataDescriptionField
=
"Location"
DataEndField
=
"End"
DataKeyField
=
"ID"
DataStartField
=
"Start"
DataSubjectField
=
"Location"
FirstDayOfWeek
=
"Monday"
LastDayOfWeek
=
"Friday"
HoursPanelTimeFormat
=
"H:mm"
OnAppointmentInsert
=
"RadScheduler1_AppointmentInsert"
OnAppointmentUpdate
=
"RadScheduler1_AppointmentUpdate"
SelectedView
=
"WeekView"
Skin
=
"Office2010Blue"
TimeZoneID
=
"GMT Standard Time"
OnAppointmentDataBound
=
"RadScheduler1_AppointmentDataBound"
EnableResourceEditing
=
"False"
OnAppointmentDelete
=
"RadScheduler1_AppointmentDelete"
Culture
=
"en-GB"
Width
=
"100%"
WorkDayEndTime
=
"18:00:00"
StartInsertingInAdvancedForm
=
"True"
Height
=
"100%"
AllowDelete
=
"True"
OnClientTimeSlotClick
=
"OnTimeSlotClick"
OnClientAppointmentDoubleClick
=
"OnCLientAppointmentDoubleClick"
OnClientAppointmentEditing
=
"OnClientAppointmentEditing"
>
<
ExportSettings
>
<
Pdf
PageTopMargin
=
"1in"
PageBottomMargin
=
"1in"
PageLeftMargin
=
"1in"
PageRightMargin
=
"1in"
></
Pdf
>
</
ExportSettings
>
<
AdvancedForm
Modal
=
"True"
EnableResourceEditing
=
"False"
/>
<
TimelineView
UserSelectable
=
"False"
ColumnHeaderDateFormat
=
"ddd-MM"
/>
<
WeekView
ColumnHeaderDateFormat
=
"ddd dd"
HeaderDateFormat
=
"ddd dd MMM"
/>
<
DayView
UserSelectable
=
"False"
/>
<
MonthView
UserSelectable
=
"False"
/>
<
AppointmentContextMenuSettings
EnableDefault
=
"True"
/>
<
TimeSlotContextMenuSettings
EnableDefault
=
"True"
/>
<
InlineEditTemplate
>
</
InlineEditTemplate
>
</
telerik:RadScheduler
>
<
p
>(Right-click calendar to create/edit entry)</
p
>
<
telerik:RadAjaxLoadingPanel
ID
=
"lp1"
runat
=
"server"
Skin
=
"Web20"
></
telerik:RadAjaxLoadingPanel
>
<%--<
script
type
=
"text/javascript"
src
=
"/_layouts/MicrosoftAjax.js"
></
script
>
<
script
type
=
"text/javascript"
src
=
"/_layouts/SP.debug.js"
></
script
>--%>
<
script
type
=
"text/javascript"
>
var check = false;
function OnTimeSlotClick(sender, args)
{
//sender.get_timeSlotContextMenus()[0].show(args.get_domEvent());
}
//Prevent Edit when appointment is double-clicked
function OnCLientAppointmentDoubleClick(sender, args)
{
//check = true;
}
function OnClientAppointmentEditing(sender, args)
{
//args.set_cancel(check);
}
</
script
>
using
System;
using
System.ComponentModel;
using
System.Drawing;
using
System.Web.UI;
using
System.Web.UI.WebControls.WebParts;
using
Microsoft.SharePoint;
using
System.Data;
using
Microsoft.SharePoint.Linq;
using
System.Collections.Generic;
using
System.Linq;
using
Telerik.Web.UI;
using
System.Diagnostics;
namespace
CommsCalendar.CCalendar
{
[ToolboxItemAttribute(
false
)]
public
partial
class
CCalendar : WebPart
{
// Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
// using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
// for production. Because the SecurityPermission attribute bypasses the security check for callers of
// your constructor, it's not recommended for production purposes.
// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
public
CCalendar()
{
}
RadAjaxManager _ajaxManager;
bool
_userHasPermission =
false
;
protected
override
void
OnInit(EventArgs e)
{
base
.OnInit(e);
InitializeControl();
_userHasPermission = CheckUserPermission();
RadScheduler1.TimeSlotContextMenus.Add(BuildTimeSlotContextMenu());
SetUpAjaxManagerOnPage();
}
protected
void
SetUpAjaxManagerOnPage()
{
RadAjaxManager currentAjaxManager = RadAjaxManager.GetCurrent(Page);
if
(currentAjaxManager ==
null
)
{
Page.Form.Controls.AddAt(0, AjaxManager);
Page.Items.Add(
typeof
(RadAjaxManager), AjaxManager);
}
}
protected
virtual
RadAjaxManager AjaxManager
{
get
{
if
(_ajaxManager ==
null
)
{
_ajaxManager = RadAjaxManager.GetCurrent(Page);
if
(_ajaxManager ==
null
)
{
_ajaxManager =
new
RadAjaxManager() { ID =
"RadAjaxManager1"
};
}
}
return
_ajaxManager;
}
}
protected
override
void
CreateChildControls()
{
}
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
RadScheduler scheduler =
this
.FindControl(
"RadScheduler1"
)
as
RadScheduler;
RadAjaxManager _manager = RadAjaxManager.GetCurrent(Page);
RadAjaxLoadingPanel lp = (RadAjaxLoadingPanel)FindControl(
"lp1"
);
_manager.AjaxSettings.AddAjaxSetting(scheduler, scheduler, lp);
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
LoadSchedulerData();
}
}
protected
RadSchedulerContextMenu BuildTimeSlotContextMenu()
{
RadSchedulerContextMenu cxt =
new
RadSchedulerContextMenu();
cxt.ID =
"MyTimeSlotContextMenu"
;
cxt.Items.Add(
new
RadMenuItem() { Text =
"Add New Appointment"
, Value =
"CommandAddAppointment"
, Enabled = _userHasPermission });
cxt.Items.Add(
new
RadMenuItem() { Text =
"Goto Today"
, Value =
"CommandGoToToday"
});
cxt.Items.Add(
new
RadMenuItem() { Text =
"Show 24 hours..."
, Value =
"CommandShow24Hours"
});
return
cxt;
}
protected
RadSchedulerContextMenu BuildAppointmentContextMenu()
{
//Not used as Radscheduler AllowEdit and AllowDelete overrides Enabled settings at this level
RadSchedulerContextMenu cxtAppContext =
new
RadSchedulerContextMenu();
cxtAppContext.ID =
"MyAppointmentContextMenu"
;
cxtAppContext.Items.Add(
new
RadMenuItem() { Text =
"MyEdit"
, Value =
"CommandShow24Hours"
, Enabled = _userHasPermission });
cxtAppContext.Items.Add(
new
RadMenuItem() { Text =
"MyDelete"
, Value =
"CommandDelete"
, Enabled = _userHasPermission });
return
cxtAppContext;
}
private
bool
CheckUserPermission()
{
bool
userHasPermission =
false
;
using
(SPSite site =
new
SPSite(SPContext.Current.Web.Url))
using
(SPWeb web = site.OpenWeb())
{
SPUser thisUser = SPContext.Current.Web.CurrentUser;
SPList appts = web.Lists[
"Calendar"
];
userHasPermission = appts.DoesUserHavePermissions(thisUser, SPBasePermissions.AddListItems);
}
return
userHasPermission;
}
protected
void
LoadSchedulerData()
{
using
(SPSite site =
new
SPSite(SPContext.Current.Web.Url))
using
(SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[
"Calendar"
];
SPListItemCollection apptCollection = list.GetItems(
new
SPQuery()
{
//Don't bother loading events more than 7 days old
Query =
"<Where><Geq><FieldRef Name='EventDate'/><Value Type='DateTime'><Today OffsetDays='-7'/></Value></Geq></Where>"
});
RadScheduler1.DataStartField =
"EventDate"
;
RadScheduler1.DataEndField =
"EndDate"
;
RadScheduler1.DataKeyField =
"ID"
;
RadScheduler1.DataSubjectField =
"Title"
;
RadScheduler1.DataDescriptionField =
"Description"
;
RadScheduler1.DataSource = apptCollection.GetDataTable();
RadScheduler1.DataBind();
}
}
protected
void
RadScheduler1_AppointmentUpdate(
object
sender, Telerik.Web.UI.AppointmentUpdateEventArgs e)
{
using
(SPSite site =
new
SPSite(SPContext.Current.Web.Url))
using
(SPWeb web = site.OpenWeb())
{
SPList calList = web.Lists[
"Calendar"
];
SPListItem appointment = calList.GetItemById((
int
)e.ModifiedAppointment.ID);
if
(appointment !=
null
)
{
appointment[
"EventDate"
] = e.ModifiedAppointment.Start;
appointment[
"EndDate"
] = e.ModifiedAppointment.End;
appointment[
"Title"
] = e.ModifiedAppointment.Subject;
appointment[
"Description"
] = e.ModifiedAppointment.Description;
appointment.Update();
}
}
LoadSchedulerData();
}
protected
void
RadScheduler1_AppointmentInsert(
object
sender, Telerik.Web.UI.AppointmentInsertEventArgs e)
{
using
(SPSite site =
new
SPSite(SPContext.Current.Web.Url))
using
(SPWeb web = site.OpenWeb())
{
SPList calList = web.Lists[
"Calendar"
];
SPListItem appointment = calList.Items.Add();
appointment[
"Title"
] = e.Appointment.Subject;
appointment[
"EventDate"
] = e.Appointment.Start;
appointment[
"EndDate"
] = e.Appointment.End;
appointment[
"Description"
] = e.Appointment.Description;
appointment.Update();
}
LoadSchedulerData();
}
protected
void
RadScheduler1_AppointmentDelete(
object
sender, AppointmentDeleteEventArgs e)
{
using
(SPSite site =
new
SPSite(SPContext.Current.Web.Url))
{
using
(SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[
"Calendar"
];
list.Items.DeleteItemById((
int
)e.Appointment.ID);
}
}
}
protected
void
RadScheduler1_AppointmentDataBound(
object
sender, SchedulerEventArgs e)
{
//We can set Edit/Delete permission here which will override the base settings of the RadScheduler
e.Appointment.AllowEdit = _userHasPermission;
e.Appointment.AllowDelete = _userHasPermission;
e.Appointment.BackColor = Color.FromArgb(255, 51, 108, 171);
e.Appointment.ForeColor = Color.FromArgb(255, 255, 255);
}
}
}