This is a migrated thread and some comments may be shown as answers.

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength

11 Answers 2227 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manish
Top achievements
Rank 1
Manish asked on 05 Jan 2016, 04:21 AM

Hi,
I am using Grid - Virtualization. But when I try to load huge data getting an error "Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property." where as also I am using  "OnNeedDataSource"

I have app.21K rows and 135+ columns.
As per my requirement I need to create Grid columns at run time as don't know how many columns and rows we be there as query output.
I have also used below code in my config file but don't get any success
 <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="2147483647" />
      </webServices>
    </scripting>
  </system.web.extensions>

 

Attaching source code files.
Can any body help me out in this.
Thanks

11 Answers, 1 is accepted

Sort by
0
Manish
Top achievements
Rank 1
answered on 05 Jan 2016, 04:33 AM

.

aspx page:
 
  <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <div id="dvGrd">
            <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1"></telerik:RadAjaxLoadingPanel>
            <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel" LoadingPanelID="RadAjaxLoadingPanel1" CssClass="demo-container">
                <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
                    GroupingEnabled="false"
                    EnableHeaderContextMenu="true" AllowPaging="true" PageSize="50" OnNeedDataSource="RadGrid1_NeedDataSource" Height="700px">
                    <MasterTableView HierarchyLoadMode="ServerOnDemand" TableLayout="Fixed">
                        <Columns>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings ReorderColumnsOnClient="true" AllowColumnsReorder="true" ColumnsReorderMethod="Reorder"
                        Virtualization-EnableCurrentPageScrollOnly="false">
                        <Virtualization EnableVirtualization="true" InitiallyCachedItemsCount="2000"
                            LoadingPanelID="RadAjaxLoadingPanel1" ItemsPerView="100" />
                        <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="500px" />
                        <Resizing AllowColumnResize="true" />
                    </ClientSettings>
                    <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
                </telerik:RadGrid>
            </telerik:RadAjaxPanel>

 

.aspx.cs page:
 
 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataTable dt =  GetListData("select  * from persons");
                GridBoundColumn boundColumn;
                boundColumn = new GridBoundColumn();
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    boundColumn = new GridBoundColumn();
                    //RadGrid1.MasterTableView.Columns.Add(boundColumn);
                    boundColumn.DataField = dt.Columns[i].ColumnName.ToString();
                    boundColumn.HeaderText = dt.Columns[i].ColumnName.ToString();
                    RadGrid1.Columns.Add(boundColumn);
                }
                RadGrid1.Width = dt.Columns.Count * 40;
                
            }
        }
 
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = GetListData("select * from persons");
        }
 

 

 

0
Pavlina
Telerik team
answered on 05 Jan 2016, 08:32 AM
Hi,

As recommended in the other forum thread you have opened with the same question you can try setting lower InitiallyCachedItemsCount and see how if this helps.
<Virtualization EnableVirtualization="true" InitiallyCachedItemsCount="800"
                            LoadingPanelID="RadAjaxLoadingPanel1" ItemsPerView="100" />

Additionally in order to avoid duplicate posts lets continue the communication on the matter only in one of the these threads.

Regards,
Pavlina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Manish
Top achievements
Rank 1
answered on 05 Jan 2016, 09:37 AM

Hi,

I managed to bind records by using InitiallyCachedItemsCount=300, but now the problem is after 300 row it is not showing any record only rendering blank rows.

0
Pavlina
Telerik team
answered on 06 Jan 2016, 04:40 PM
Hello,

Could you please specify which version you are using in your project? Also confirm that the issue exists with the latest version of the controls.

Regards,
Pavlina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Manish
Top achievements
Rank 1
answered on 07 Jan 2016, 03:52 AM

Hi,

I am using  Telerik v.2015.3.1111.35. and having above mentioned issue. 

 

0
Manish
Top achievements
Rank 1
answered on 08 Jan 2016, 03:54 AM

Hi, 

I have mentioned Telerik version as you guys asked

anybody provide me some sort of help regarding my issue.

0
Manish
Top achievements
Rank 1
answered on 11 Jan 2016, 03:01 AM

Hi Team,

Can you provide me some sort of support or guidance for my above issue, I need to apply in one of my solution.

 

0
Pavlina
Telerik team
answered on 11 Jan 2016, 04:14 PM
Hello,

You could try lowering the number of records per page in order to minimize the JSON data serialized to the client. Additionally, have you tried specifying the maximum value (2,147,483,647) for the maxJsonLength? If your issue still persists you could prepare a sample project showing the unwanted behavior so we could debug it on our side and advice you with the best possible solution.

Thank you for your cooperation in advance.

Regards,

Pavlina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Manish
Top achievements
Rank 1
answered on 18 Jan 2016, 04:43 AM

Hi,

 Below is my code. This is only stuff I am using in my code

 

0
Manish
Top achievements
Rank 1
answered on 18 Jan 2016, 04:44 AM
.aspx code:
 
 <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <div id="dvGrd">
            <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1"></telerik:RadAjaxLoadingPanel>
            <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel" LoadingPanelID="RadAjaxLoadingPanel1" CssClass="demo-container" Height="100%">
                <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" Height="100%"
                    GroupingEnabled="false" EnableHeaderContextMenu="true" AllowPaging="true" PageSize="50" OnNeedDataSource="RadGrid1_NeedDataSource">
                    <MasterTableView HierarchyLoadMode="ServerOnDemand" TableLayout="Fixed">
                        <Columns>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings ReorderColumnsOnClient="true" AllowColumnsReorder="true" ColumnsReorderMethod="Reorder">
                        <Virtualization EnableVirtualization="true" InitiallyCachedItemsCount="300"
                            LoadingPanelID="RadAjaxLoadingPanel1" ItemsPerView="100" />
                        <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="500px" />
                        <Resizing AllowColumnResize="true" />
                    </ClientSettings>
                    <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
                </telerik:RadGrid>
            </telerik:RadAjaxPanel>
        </div>
 
aspx.cs code
 
private static string connection = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataTable dt =  GetListData("select ROW_NUMBER() over(order by persons_code) rnum,* from persons");
                GridBoundColumn boundColumn;
                boundColumn = new GridBoundColumn();
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    boundColumn = new GridBoundColumn();
                    //RadGrid1.MasterTableView.Columns.Add(boundColumn);
                    boundColumn.DataField = dt.Columns[i].ColumnName.ToString();
                    boundColumn.HeaderText = dt.Columns[i].ColumnName.ToString();
                    boundColumn.ItemStyle.Width = Unit.Pixel(125);
                    boundColumn.HeaderStyle.Width= Unit.Pixel(125);
                    RadGrid1.Columns.Add(boundColumn);
                }
                //RadGrid1.Width = dt.Columns.Count * 70;
                
            }
        }
        public static DataTable GetListData(string query)
        {
            DataTable dt = new DataTable();
            using (SqlConnection con = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand(query, con))
                {
                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(dt);
                }
            }
            return dt;
        }
 
        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = GetListData("select ROW_NUMBER() over(order by persons_code) rnum,* from persons");
        }
    }
0
Pavlina
Telerik team
answered on 18 Jan 2016, 04:17 PM
Hi,

Have you tried setting the maxJsonLength property in the web.config to a greater value as recommended in the previous post and what was the result? For example to 2147483644, which is the maximum value possible?
<configuration>
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="2147483644"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration

If this not helps it will be helpful if you could send us a small example where the described issue could be reproduced . You could open a formal support ticket from your Telerik account and attach a ZIP file there. Thus we will be able to debug the project and provide a solution. 

Regards,
Pavlina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Manish
Top achievements
Rank 1
Answers by
Manish
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or