0

I am trying to optimise the load of a page that has over 5000 rows of data being returned.

Instead of letting the ASP.Net Webforms code behind produce the HTML I am trying to achieve this using JQuery.

Please see my code below.

$.ajax({
            type: "POST",
            url: "TeamChecks.aspx/GetDataTables",
            data: JSON.stringify(params),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                //console.log(data.d);

                var table = $('#hidJson_tbl_2').DataTable({
                    "ajax": data.d,
                    "columns:": [
                        { "data": "CaseHandlerStaffNumber" },
                        { "data": "RiskProfileText" },
                        { "data": "AssignedCheckerStaffNumber" },
                        { "data": "FeedbackUserStaffNumber" },
                        { "data": "ComplaintRef" },
                        { "data": "ChildComplaintRef" },
                        { "data": "CaseTypeText" },
                        { "data": "CheckGrade" }
                    ]
                });
            },
            error: function (data) {
                console.log(data);
            }
        }

which calls method that uses NewtonSoft Json.Net

TeamChecks tc = new TeamChecks();

DataTable dtMc = default(DataTable);
dtMc = tc.Get_DatatableFor_GridView(userId, CheckStatusId);

string jsonResult = null;
jsonResult = Newtonsoft.Json.JsonConvert.SerializeObject(dtMc);
jsonResult = jsonResult.Replace("[{", "{data:[{").Replace("}]", "}]}");
return jsonResult;

The example I am loosely following because I need to get the values from code behind rather than a text file can be found here https://datatables.net/reference/option/ajax

The error message that I am getting is

"{"Message":"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.","StackTrace":" at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}"

I would be grateful if someone could help me understand where I am going wrong and what I need to do in order to resolve this.

Thanks

1
  • I'm not sure how to resolve, but the bit that sticks out for me is the "The length of the string exceeds the value set on the maxJsonLength property" in your error message; seems that your 5000 records are spilling out the side. Sorry if this isn't much help - just thought it might give you a pointer where to go from here Commented May 12, 2016 at 13:07

1 Answer 1

1

Your problem is with the SerializeObject, you have to set maxJsonLength to a big number to suit your case. see this answer here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that's got rid of that error and now I have another to work on

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.