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

JSON JavaScriptSerializer. The length of the string exceed the value on the maxJsonLength property.

2 Answers 311 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laurie
Top achievements
Rank 1
Laurie asked on 19 Jun 2013, 03:41 PM
Hello,

I'm having an issue with a radgrid that populates data from a linq query.  The grid uses an OnItemDataBound and OnItemCommand method.

Looking at the page source after being compiled, the viewstate looks absolutely massive, as if the grid is trying to stick the binary file in the viewstate somehow.

I tried increasing the size of the maxJsonLength through web.config to no avail.

The specific error is:

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

I'm uploading a file, and then clicking back to a page that rebinds the radgrid containing an attachment column which triggers the onitemcommand method. 

Thanks ahead of time.


ASPX:

<telerik:RadGrid ID="procGrid" runat="server" AutoGenerateColumns="False" 
                    CellSpacing="0" GridLines="None" onneeddatasource="procGrid_NeedDataSource" OnItemDataBound="grdProcedures_ItemDataBound2" OnItemCommand="grdFiles_ItemCommand">
<MasterTableView>
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
  
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
  
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
  
    <Columns>
        <telerik:GridBoundColumn FilterControlAltText="Filter column column" 
            UniqueName="column" DataField="name" HeaderText="Name">
            <ItemStyle Width="400px" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Id" 
            FilterControlAltText="Filter column1 column" UniqueName="column1">
        </telerik:GridBoundColumn>
        <telerik:GridHyperLinkColumn AllowSorting="False" 
            FilterControlAltText="Filter column2 column" UniqueName="column2" 
            HeaderText="Review">
            <ItemStyle Width="100px" />
        </telerik:GridHyperLinkColumn>
                    <telerik:GridAttachmentColumn FileName="attachment" 
                        FilterControlAltText="Filter procedure_document column" HeaderText="Procedures" 
                        UniqueName="procedure_document"
                        AttachmentDataField="procedure_document" 
                        AttachmentKeyFields="procedure_document" 
                        Text="View Procedure" >
                         
                    </telerik:GridAttachmentColumn>
    </Columns>
  
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
  
<FilterMenu EnableImageSprites="False"></FilterMenu>
  
<ClientSettings EnablePostBackOnRowClick="true">
  
  
</ClientSettings>
                </telerik:RadGrid>


CS:


protected void grdProcedures_ItemDataBound2(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        string ProcId = item["column1"].Text;
        HyperLink link = (HyperLink)item["column2"].Controls[0];
        link.Text = "Edit Procedure";
        string url = "~/procedure.aspx?AuditType=" + AuditType + "&AuditID=" + AuditID + "&StandardID=" + StandardID + "&ProcedureID=" + ProcId;
        link.NavigateUrl = url;
    }
}
protected void grdFiles_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.DownloadAttachmentCommandName)
    {
        using (var db = new isoAuditModelContainer())
        {
            RadAjaxManager Manager = new RadAjaxManager();
            Manager.EnableAJAX = false;
            GridDownloadAttachmentCommandEventArgs args = e as GridDownloadAttachmentCommandEventArgs;
            GridDataItem item = (GridDataItem)e.Item;
            string fileName = args.FileName;
            string ProcId = item["column1"].Text;
            int ProcId2 = Convert.ToInt16(ProcId);
            //int attachmentId = (int)args.AttachmentKeyValues["procedure_document"];
            var query = (from x in db.procedures where x.Id == ProcId2 select x).First();
            string extension = query.file_extension;
            byte[] binaryData = (byte[])query.procedure_document;
            Response.Clear();
            //Response.ContentType = query.fileExtension;
            Response.AddHeader("content-disposition", "attachment; filename=" + fileName + extension);
            Response.BinaryWrite(binaryData);
            Response.OutputStream.Write(binaryData, 0, binaryData.Length);
            Response.Flush();
            Response.Close();
            Response.End();
        }
    }
}






2 Answers, 1 is accepted

Sort by
0
Laurie
Top achievements
Rank 1
answered on 19 Jun 2013, 03:43 PM
I should mention that this works okay if the file is 500 KB or smaller.  However, when I look at the viewstate of the 500KB or smaller file, it's still enormous.
0
Kostadin
Telerik team
answered on 20 Jun 2013, 12:56 PM
Hi Laurie,

I answered the support ticket related with the following forum thread. I would suggest to continue our conversation there.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Laurie
Top achievements
Rank 1
Answers by
Laurie
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or