Using jQuery’s Each method to iterate through a JavaScript array

0

Posted by Joe | Posted in JavaScript, jQuery | Posted on 30-12-2009

The Each method in jQuery is pretty useful and can be used to iterate through the elements within a jQuery object.

I’ve been using it recently to iterate through JavaScript arrays.  It saves having to use a for loop and the code looks nicer.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

JSON Serialization using the DataContractJsonSerializer and C#

0

Posted by Joe | Posted in ASP.NET, C#, JavaScript | Posted on 29-12-2009

Download source code

Previously I’d done JSON serialization using the JavaScriptSerializer which is part of AJAX Extensions 1.0, but this is now obsolete.

.NET 3.5 introduced the DataContractJsonSerializer class.  The class sits in the System.Runtime.Serialization.Json namespace which is curiously hidden away in the System.ServiceModel.Web assembly.

The DataContractJsonSerializer can serialize a class that contains the Serializable attribute or any class defined as a DataContract.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

JavaScript inline if statement

0

Posted by Joe | Posted in JavaScript | Posted on 29-12-2009

The JavaScript inline if statement is identical to the one in C#:

var forename = (gender == 'male') ? 'Joe' : 'Emily';

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

Escape curly braces when using String.Format or StringBuilder.AppendFormat

1

Posted by Joe | Posted in C#, JavaScript | Posted on 29-12-2009

I was using the StringBuilder to create a JSON string which included an array and therefore curly braces, but I got an exception as curly braces are used to define the parameters for the format.

sb.AppendFormat("{\"Forename\":\"{0}\",\"Surname\":\"{1}\"}", person.Forename, person.Surname);

At first I tried adding a backslash which is used to escape the quotation mark but this didn’t work, so I tried the double character trick but adding two curly braces which seems to do the job.

sb.AppendFormat("{{\"Forename\":\"{0}\",\"Surname\":\"{1}\"}}", person.Forename, person.Surname);

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

Linq to SQL Tutorial – Linq to SQL Generic Framework using reflection

0

Posted by Joe | Posted in ASP.NET, C#, Linq | Posted on 28-12-2009

Download source code

In a previous post; Base Repository/Business Logic wrapper, I talked about a basic Linq to SQL Framework I created. I then extended it in my ObjectDataSource binding with paging and sorting post to show how to use it with the ObjectDataSource.

The problem was that although it worked quite nicely for getting all records and getting by ID, if I wanted to perform any specific filtering I had to create a derived repository class with a specific method for each query.

In this post I’ll explain how I have extended this framework using reflection to allow filtering on multiple columns without having to created separate repository objects.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit