Well it can be done in MVC and WebAPI. But is there a way to change default serializer in ASP.Net Web Forms? We are using Newtonsoft.JSON to send objects over the wire. It uses CamelCasePropertyName so FirstName in C# becomes firstName in JSON. Now when we need to pass objects back to server for web methods to consume, we have to create new object with FirstName property instead of firstName otherwise ASP.Net complains and request fails.
I sincerely hope that there is something very easy and straight-forward that I'm missing.
EDIT:- Well that all is well and good to overcome these issues by implementing custom converts for types or by using web service or wcf or moving to MVC/WebAPI. What we are trying to achieve is by using page method with classic (if it is right to say so) ASP.Net web-forms.
I was looking for some way to plug in JSON.Net serializer (Newtonsoft one) in place of default JavaScriptSerializer as we can do in MVC/WebAPI stack.
Sample code:
//class
public class Student
{
public string FirstName{get;set;}
}
//WebMethod in ASPX code-behind
[WebMethod]
public static string UpdateStudent(Student s)
{
//code to update object and send some response back.
}
MAIN ISSUE
When getting data from browser in json format with camel case, default JavaScriptSerialization is not able to handle property names.
But if I send custom object like:
var o={FirstName:'John'};
it works!!!
JSON.Netto serialize objects. The issue is when browser is sending data toPageMethod, it is not able to properly convert properties from camel case to pascal case.PageMethod(orWebMethod). I've added sample code.