Posted by Joe | Posted in ASP.NET, Ajax, JavaScript | Posted on 29-06-2010
JSON doesn’t have a standard way to represent a date. You can read about the reasons behind this here.
If you are using an ASMX web service returning JSON then you’ll find it serializes the DateTime object to a string that looks like this:
/Date(1278943200000)/
The numer in this string is the number of milliseconds since January 1st 1970 UTC, and this number can be used as a constructor argument to the JavaScript Date object. So all we need to do is extract the number of milliseconds from the string. This can be done easily using the regular expression shown in the post linked above.
var dateString = "/Date(1278943200000)/";
var date = new Date(parseInt(dateString.replace(/\/Date\((\d+)\)\//, '$1')));
In the above example I’ve manually set the date string, but you may get this from an AJAX response from the ASMX web service. I then create a new Date object by using the regular expression and parsing the result at an integer.

Posted by Joe | Posted in ASP.NET, C# | Posted on 16-04-2010
Download source
When creating web applications with ASP.NET developers will usually create User Controls or Custom Server Controls. User Controls have the ASCX extension and allow developers to group together ASP.NET controls and functionality into a reusable control. Custom Controls are a bit more complex and require the developer to define the html that the control generates as well as all it’s functionality. It is also possible to add child ASP.NET controls to a Server Control and have the control render those child control and maintain their viewstate with little work.
In .NET 2.0 the abstract CompositeControl class was introduced, which is derived from WebControl but also uses the interfaces INamingContainer, which makes sure all child controls have a unique ID, and ICompositeControlDesignerAccessor which is used to allow the control to render the control automatically at design time based on the child controls. The CompositeControl also ensures that child controls are always created which saves using the EnsureChildControls method that many Custom Control developers will be familiar with.
In this post I’ll explain how to create a simple Composite Custom Control and how to customise the HTML that it renders.
Read the rest of this entry »

Posted by Joe | Posted in ASP.NET, jQuery | Posted on 18-03-2010
Posted by Joe | Posted in MVC | Posted on 17-02-2010
Posted by Joe | Posted in Ajax, MVC, jQuery | Posted on 16-02-2010
Posted by Joe | Posted in ASP.NET, Ajax, JavaScript, jQuery | Posted on 12-01-2010
Download source
In this post I talked about how to use the jTemplates plugin for jQuery. Using my final example in the post I thought it would be cool to try and add some ‘edit in place’ functionality to the table.
For this to work I’ve created a Data Access Layer using Linq to XML. My web service then uses this DAL to save and retrieve my data.
Read the rest of this entry »

Posted by Joe | Posted in ASP.NET, C#, Linq, XML | Posted on 08-01-2010
Download source
This is an introduction to Linq to XML showing how to read, insert, update and delete from an XML file.
Read the rest of this entry »

Posted by Joe | Posted in ASP.NET, Ajax, JavaScript, jQuery | Posted on 05-01-2010
Download source
A guy in work introduced me to jTemplates, a template engine plugin for jQuery. It allows you to easily bind JavaScript objects to a defined template and also has some other nifty features.
I’ve found jTemplates to be particularly good when using ajax to display any information quickly and easily.
First I’ll explain how to create a simple template to display data, and then how to use the foreach and cycle features.
Read the rest of this entry »

Download source
Making ajax calls to an ASP.NET web service using jQuery is too easy. In this post I’ll explain how to do it!
Read the rest of this entry »

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 »
