search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Navigator and Calendar not connecting

Asked by Karsten
14 years ago.

Hi,

I'm struggling getting a navigator and month calendar connected inside a (SharePoint) Webpart. This restricts me to doing all coding in the code behind. To isolate the problem I've recreated the code in a normal asp.net webapp page. The behaviour still is the same, so im quite sure that SharePoint is not the problem.

daypilot.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="daypilot.aspx.cs" Inherits="TestAjaxGrid.daypilot" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>

<script src="common.js" type="text/javascript"></script>
<script src="month.js" type="text/javascript"></script>
<script src="Navigator.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="mydiv" runat="server">

</div>
</form>
</body>
</html>

Codebehind:

public partial class daypilot : System.Web.UI.Page
{
protected DayPilotMonth calendar;
protected DayPilotNavigator navigator;
private bool _error = false;

protected void Page_Load(object sender, EventArgs e)
{

if (!_error)
{
try
{

base.CreateChildControls();
navigator = new DayPilotNavigator();
navigator.ClientObjectName = "dpnavi";
navigator.BoundDayPilotID = "mycalendar";
navigator.ID = "mynavigator";
navigator.BindCommand = "navigate";

// folgendes ist wichtig: sonst luft man in 403 fehler wenn der
// user nicht ausreichende rechte hat (admin!?)
navigator.ResourcesStatic = true;
navigator.ResourcesPath = "/sites/arcnet/_layouts/arcnet/daypilot";
navigator.SelectMode = NavigatorSelectMode.Month;
navigator.ShowMonths = 1;
navigator.DataStartField = "StartDate";
navigator.DataEndField = "DueDate";
navigator.VisibleRangeChangedHandling = UserActionHandling.CallBack;
navigator.VisibleRangeChanged += new DayPilot.Web.Ui.Events.Navigator.VisibleRangeChangedEventHandler(navigator_VisibleRangeChanged);

calendar = new DayPilotMonth();
calendar.ID = "mycalendar";
calendar.ClientObjectName = "dpm";

// folgendes ist wichtig: sonst luft man in 403 fehler wenn der
// user nicht ausreichende rechte hat (admin!?)
calendar.ResourcesStatic = true;
calendar.ResourcesPath = "/sites/arcnet/_layouts/arcnet/daypilot";
calendar.EventEndTime = false;
calendar.EventStartTime = false;
calendar.EventHeight = 22;
calendar.EventFontSize = "10pt";

calendar.DataStartField = "StartDate";
calendar.DataEndField = "DueDate";
calendar.DataTextField = "Title";
calendar.DataValueField = "GID";
calendar.DataTagFields = "EventType, Status, AssignedTo";

//calendar.EventClickHandling = EventClickHandlingEnum.JavaScript;
//calendar.EventClickJavaScript = "openCalendarActivityPopup(e);";

calendar.Command += new DayPilot.Web.Ui.Events.CommandEventHandler(calendar_Command);
//calendar.BeforeEventRender += new DayPilot.Web.Ui.Events.Month.BeforeEventRenderEventHandler(calendar_BeforeEventRender);
//calendar.EventResizeHandling = UserActionHandling.JavaScript;
//calendar.EventResizeJavaScript = "calendarItemResized(e, newStart, newEnd);";


Table tb = new Table();
tb.Width = new Unit("100%");
// row for the "new" button
TableRow tr = new TableRow();
tb.Rows.Add(tr);

// empty cell
TableCell tc0 = new TableCell();
tc0.VerticalAlign = VerticalAlign.Top;
tc0.Width = new Unit("150px");
tc0.Controls.Add(new Literal());
tr.Cells.Add(tc0);

// add the "new" button
tc0 = new TableCell();
tc0.VerticalAlign = VerticalAlign.Top;
Literal lt = new Literal();
lt.Text = "<button id='createCalendarEntry' style='padding:3px 0' onclick='return false;'><img src='/_layouts/arcnet/images/icons/btnNew.gif' style='margin:0 5px 0 0px' />Create New Calendar Entry</button>";
tc0.Controls.Add(lt);
tr.Cells.Add(tc0);

//add navigator and month control
tr = new TableRow();
tb.Rows.Add(tr);

TableCell tc1 = new TableCell();
tc1.VerticalAlign = VerticalAlign.Top;
tc1.Width = new Unit("150px");
tc1.Controls.Add(navigator);
tr.Cells.Add(tc1);

TableCell tc2 = new TableCell();
tc2.VerticalAlign = VerticalAlign.Top;
tc2.Controls.Add(calendar);
tr.Cells.Add(tc2);
mydiv.Controls.Add(tb);

if (!this.Page.IsPostBack)
{
navigator.StartDate = DateTime.Today;
calendar.StartDate = DateTime.Today;
loadData();
//set start values

}

}
catch (Exception ex)
{
HandleException(ex);
}
}
}

void navigator_TimeRangeSelected(object sender, DayPilot.Web.Ui.Events.TimeRangeSelectedEventArgs e)
{
throw new NotImplementedException();
}

void navigator_VisibleRangeChanged(object sender, DayPilot.Web.Ui.Events.Navigator.VisibleRangeChangedEventArgs e)
{
HttpContext.Current.Response.Write("<br>navigate..");
//throw new NotImplementedException();
//int days = (int)(navigator.VisibleEnd - navigator.VisibleStart).TotalDays;
calendar.StartDate = navigator.StartDate;
loadData();

calendar.Update(CallBackUpdateType.Full);
//navigator.DataSource = //dbGetEvents(DayPilotNavigator1.VisibleStart, days);
//navigator.DataBind();


}

/// <summary>
/// this event is used to manipulate the event html before rendering
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void calendar_BeforeEventRender(object sender, DayPilot.Web.Ui.Events.Month.BeforeEventRenderEventArgs e)
{
string eventType = e.Tag["EventType"];
if (eventType != null)
eventType = eventType.ToLower();

switch (eventType)
{
case "calendar":
e.InnerHTML += "&nbsp;<img src='/sites/arcnet/_layouts/arcnet/images/icons/calendar_day.png' />";
e.BackgroundColor = "lightgreen";
break;

case "activity":
e.InnerHTML += "&nbsp;<img src='/sites/arcnet/_layouts/arcnet/images/icons/flag.png' />";
e.BackgroundColor = "lightblue";
break;
}

}

void calendar_Command(object sender, DayPilot.Web.Ui.Events.CommandEventArgs e)
{
//HttpContext.Current.Response.Write("entered command");
switch (e.Command)
{
case "refresh":
// called after a new calendar item has been created
loadData();
calendar.Update(CallBackUpdateType.Full);
break;
case "navigate":
HttpContext.Current.Response.Write("<br>navigate..");
DateTime start = (DateTime)e.Data["start"];
DateTime end = (DateTime)e.Data["end"];
calendar.StartDate = start;
loadData();
calendar.Update(CallBackUpdateType.Full);
break;
//case "filter":
// // not used currently us
// calendar.DataSource = getData(calendar.VisibleStart, calendar.VisibleEnd, (string)calendar.ClientState["filter"]);
// calendar.DataBind();
// calendar.Update(CallBackUpdateType.EventsOnly);
// break;
}

}

private void loadData()
{
//jsARCNetContext ctx = new jsARCNetContext();

//if (ctx.CurrentUserCalendarListId == "")
// throw new ApplicationException("No calendar has been defined for you");

//////////////////////////////////////////

////string bensl = SPContext.Current.Web.CurrentUser.GetArcnetBensl();
//string bensl = "dev_administrator";
////String[] bensls = new String[] { bensl };
//string[] benslarray = new string[1];
//benslarray[0] = bensl;
//GetCalendarsForBenslsCommand cmd = new GetCalendarsForBenslsCommand(benslarray, navigator.VisibleStart, navigator.VisibleEnd);
//cmd.Invoke();

//DataTable dtActivities = Tools.GetEmptyActivityTable();
//DataTable dtActCal = Tools.MergeActivtiesAndCalenderDataTable(dtActivities, cmd.ResultsData);

//calendar.DataSource = dtActivities;
//navigator.DataSource = dtActivities;
calendar.DataBind();
navigator.DataBind();

}

/// <summary>
/// Clear all child controls and add an error message for display.
/// </summary>
/// <param name="ex"></param>
private void HandleException(Exception ex)
{
this._error = true;
this.Controls.Clear();
this.Controls.Add(new LiteralControl(ex.Message));
}

}

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.