Hi, I have this implemented and it works great http://arshaw.com/fullcalendar/. I want to load my events from either a .ashx file or .asmx file and I can't seem to figure it out for the life of me. When I hard code the events in the javascript everything
works great, but when I try to return the events from a .ashx or .asmx file it doesn't work at all. What am I doing wrong? The code hits my breakpoint on my function in the .ashx and I get no errors. Here is my .ashx example:
<script type='text/javascript'>
$(document).ready(function () {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function (start, end, allDay) {
var title = prompt('Event Title:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
},
editable: true,
events: "Handler1.ashx"
});
});
</script>
//Here is the .ashx function that gets called
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
context.Response.Write("[{title: 'Long Event', start: '2013-02-05', end: '2013-02-23'}]");
}
in the above sample page, it load external events (via js code) from the "json-events.php". So you can just use fiddler or IE development tool bar to capture the HTTP response content of the "json-events.php" request to see what kind of data it returns.
Based on my local test, here is the response data I've got via IE dev toolbar:
So what the json-events.php returns is just a JSON array. Then, what you need to do is let your ASP.NET httphandler or even a simple ASP.NET page return the same format JSON data.
epatmalnieks
Member
184 Points
249 Posts
Load events into calendar
Feb 23, 2013 09:44 PM|LINK
Hi, I have this implemented and it works great http://arshaw.com/fullcalendar/. I want to load my events from either a .ashx file or .asmx file and I can't seem to figure it out for the life of me. When I hard code the events in the javascript everything works great, but when I try to return the events from a .ashx or .asmx file it doesn't work at all. What am I doing wrong? The code hits my breakpoint on my function in the .ashx and I get no errors. Here is my .ashx example:
<script type='text/javascript'> $(document).ready(function () { var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); var calendar = $('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, selectable: true, selectHelper: true, select: function (start, end, allDay) { var title = prompt('Event Title:'); if (title) { calendar.fullCalendar('renderEvent', { title: title, start: start, end: end, allDay: allDay }, true // make the event "stick" ); } calendar.fullCalendar('unselect'); }, editable: true, events: "Handler1.ashx" }); }); </script> //Here is the .ashx function that gets called public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; context.Response.Write("[{title: 'Long Event', start: '2013-02-05', end: '2013-02-23'}]"); }Steven Cheng...
Contributor
4219 Points
548 Posts
Microsoft
Moderator
Re: Load events into calendar
Mar 07, 2013 02:16 AM|LINK
Hi epatmalnieks,
If I understand correctly, what you need is to achieve the goal of the following demo page:
http://arshaw.com/js/fullcalendar-1.5.4/demos/json.html
in the above sample page, it load external events (via js code) from the "json-events.php". So you can just use fiddler or IE development tool bar to capture the HTTP response content of the "json-events.php" request to see what kind of data it returns. Based on my local test, here is the response data I've got via IE dev toolbar:
[{"id":111,"title":"Event1","start":"2013-03-10","url":"http:\/\/yahoo.com\/"},{"id":222,"title":"Event2","start":"2013-03-20","end":"2013-03-22","url":"http:\/\/yahoo.com\/"}]So what the json-events.php returns is just a JSON array. Then, what you need to do is let your ASP.NET httphandler or even a simple ASP.NET page return the same format JSON data.
#HTTPHandler with JSON Data
http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/
To generate JSON data in server-side .NET code, you can use various means such as:
#An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET
http://msdn.microsoft.com/en-us/library/bb299886.aspx
Feedback to us
Microsoft One Code Framework