Monday, February 21, 2011

Full Calendar 1-4.10

After a year of not playing with FullCalendar it was brought to my attention that my examples no longer work with version 1-4.10 of  FullCalendar. So I took my sample code and modified it to work with the latest version of FullCalendar and ASP.NET (VB).  The problems are still the same, just in different places.

You need to still modify the start / end param names (now  called startParam and endParam) to use another date name, I prefer startDate and endDate.  If you open the fullcalendar.js file you will find these around line 43.


//startParam: 'start',
//endParam: 'end',
startParam: 'startDate',
endParam: 'endDate' 

Next you need to a search for .ajax (or skip to line 923) and modify the lines to add a couple key points to make this work with an ASP webservice.

 $.ajax({
url: source,
type: 'POST',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(params),
cache: options.cacheParam 
false, // don't let jquery prevent caching if cacheParam is being used
success: function(events) {
popLoading();
callback(eval(events.d));
}


The last change was to create your webservice that will post your calendar events from your database to the calendar via the jquery ajax call. 

    <WebMethod()> _
    Public Function EventList(ByVal startDate As String, ByVal endDate As String) As String
        ' List to hold events
        Dim events As List(Of CalendarDTO) = New List(Of CalendarDTO)()

        Dim starting As DateTime = FromUnixTimespan(startDate)
        ' Loop through events to be added
        For i As Integer = 0 To 4
            ' Create a new event and start to populate
            Dim value As CalendarDTO = New CalendarDTO()
            ' Date is required to be in a unix format
            value.StartDate = ToUnixTimespan(starting.AddDays(i * 2))
            value.id = i
            value.title = "Title of event number " + i.ToString()

            If i Mod 2 = 1 Then ' if even we will add an end date
                value.EndDate = ToUnixTimespan(starting.AddDays(1 + (i * 3)))
            End If
            events.Add(value)
        Next
        ' Serialize the return value so it can be decoded in java.
        Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
        Dim returnvalue As String = js.Serialize(events).Replace("StartDate", "start").Replace("EndDate", "end")

        Return ret


As promised here is the full sample code to get fullcalendar working with a ASP webservice.

On a side note.. Have you read the latest Scot Harvath book, its well worth the read!



Enjoy!


Sunday, February 6, 2011

Silverlight and the dreaded 2104 error

So I am working on my latest side project (learning Silverlight 4) and the samples from the book I am reading Microsoft Silverlight 4 Data and Services Cookbook are causing errors, not all of them, just most of them.  Here are the problems I encountered and how I resolved them.

First error was the One or more projects in the solution could not be loaded error. This was a pretty simple fix, right click on the project and select edit and then change the v3.0 to v4.0.  Next just click save, close the file and right click on the project, selecting Reload Project. 

Problem solved, the project loads, time for a coke and a smile?  Not always.  The next error I ran across was a freaky Webpage Error, Line 56, Error: Unhandled Error in Silverlight Application Code: 2104. 

This error had me stumped for awhile, with many solutions saying to add the .xap extension mime type under IIS6 or IIS7. Only problem, I am on a development machine and not using IIS, so what do I do.


Open your project properties, click on the Silverlight tab, and click Add.. Select the Silverlight 4 application that is being built, leave the destination the default ClientBin and click Add. 

The problem that took me many hours to resolve fixed in less than a minute of your time.

As for the book I am still working on it but with the samples working it is very detailed and covers both WCF webservices as well as WCF RIA web services.  Give it a look if you are working on Silverlight 4 like me!