FullCalendar events from asp.net ASHX page not displaying

Posted by Steve Howard on Stack Overflow See other posts from Stack Overflow or by Steve Howard
Published on 2010-06-07T14:58:19Z Indexed on 2010/06/07 15:02 UTC
Read the original article Hit count: 1146

Filed under:
|
|

Hi

I have been trying to add some events to the fullCalendar using a call to a ASHX page using the following code.

Page script:

<script type="text/javascript">


    $(document).ready(function() {
        $('#calendar').fullCalendar({
header: {
 left: 'prev,next today', center: 'title', right: 'month, agendaWeek,agendaDay'
},
events: 'FullCalendarEvents.ashx'

})
});

c# code:

public class EventsData
{
    public int id { get; set; }
    public string title { get; set; }
    public string start { get; set; }
    public string end { get; set; }
    public string url { get; set; }
    public int accountId { get; set; }
}

public class FullCalendarEvents : IHttpHandler
{

    private static List<EventsData> testEventsData = new List<EventsData>
    {
        new EventsData {accountId = 0, title = "test 1", start = DateTime.Now.ToString("yyyy-MM-dd"), id=0},
        new EventsData{ accountId = 1, title="test 2", start = DateTime.Now.AddHours(2).ToString("yyyy-MM-dd"), id=2}
    };

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "application/json.";
        context.Response.Write(GetEventData());
    }

    private string GetEventData()
    {
        List<EventsData> ed = testEventsData;
        StringBuilder sb = new StringBuilder();

        sb.Append("[");

        foreach (var data in ed)
        {
            sb.Append("{");
            sb.Append(string.Format("id: {0},", data.id));
            sb.Append(string.Format("title:'{0}',", data.title));
            sb.Append(string.Format("start: '{0}',", data.start));
            sb.Append("allDay: false");
            sb.Append("},");
        }
        sb.Remove(sb.Length - 1, 1);
        sb.Append("]");
        return sb.ToString();
    }


}

The ASHX page gets called and returnd the following data:

[{id: 0,title:'test 1',start: '2010-06-07',allDay: false},{id: 2,title:'test 2',start: '2010-06-07',allDay: false}]

The call to the ASHX page does not display any results, but if I paste the values returned directly into the events it displays correctly. I am I have been trying to get this code to work for a day now and I can't see why the events are not getting set.

Any help or advise on how I can get this to work would be appreciated.

Steve

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about events