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

RadUpload "Invalid JSON primitive: C."

4 Answers 387 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steele
Top achievements
Rank 1
Steele asked on 10 Dec 2010, 06:54 AM
Hi All,
I am battling to get the RadUpload control working in a EditItemTemplate.
I have followed the examples, tried other solutions from the forums, but to no avail.
After stripping everything back I have the following error :
Server Error in '/' Application.
--------------------------------------------------------------------------------
  
Invalid JSON primitive: C. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
Exception Details: System.ArgumentException: Invalid JSON primitive: C.
  
Source Error: 
  
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
  
Stack Trace: 
  
  
[ArgumentException: Invalid JSON primitive: C.]
   System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() +562290
   System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) +263
   System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) +80
   System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) +44
   System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(String input) +74
   Telerik.Web.UI.RadUpload.LoadPostData(String postDataKey, NameValueCollection postCollection) +149
   Telerik.Web.UI.RadWebControl.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +42
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +8910120
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +878
  
   
  
  
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

It must be a problem with my base understanding of the controls, since there really isn't much to my attempts.  Below I have included my stand-alone test aspx and code behind :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UploadTesting.aspx.cs"
    Inherits="Audit.Testing.UploadTesting" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function conditionalPostback(sender, eventArgs) {
                var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
                if (eventArgs.get_eventTarget().match(theRegexp)) {
                    if (upload && upload.getFileInputs()[0].value != "") {
                        alert('ajax off');
                        eventArgs.EnableAjax = false;
                    }
                }
            }
  
            var upload = null;
  
            function uploadFileSelected(sender, args) {
                upload = sender;
                var uploadContainer = sender.get_element();
                var editTable = uploadContainer.parentNode.parentNode.parentNode.parentNode;
                var fileNameTextBox = editTable.rows[0].cells[1].getElementsByTagName('input')[0];
  
                fileNameTextBox.value = args.get_fileInputField().title;
            }
  
  
        </script>
    </telerik:RadCodeBlock>
    <div>
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"
            OnItemCreated="RadGrid1_ItemCreated" OnNeedDataSource="RadGrid1_NeedDataSource"
            OnInsertCommand="RadGrid1_InsertCommand">
            <MasterTableView CommandItemDisplay="Top" DataKeyNames="Id">
                <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                <RowIndicatorColumn>
                    <HeaderStyle Width="20px"></HeaderStyle>
                </RowIndicatorColumn>
                <ExpandCollapseColumn>
                    <HeaderStyle Width="20px"></HeaderStyle>
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridTemplateColumn HeaderText="File" UniqueName="FileUploader">
                        <EditItemTemplate>
                            <telerik:RadUpload ID="FileUploader" runat="server" ControlObjectsVisibility="RemoveButtons"
                                MaxFileInputsCount="1" MaxFileSize="4000000" >
                            </telerik:RadUpload>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblFilename" runat="server" Text='<%# Eval("Filename") %>'></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
            <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default">
            </HeaderContextMenu>
        </telerik:RadGrid>
    </div>
    <telerik:RadAjaxManager runat="server">
    </telerik:RadAjaxManager>
    </form>
</body>
</html>

Code behind :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
  
namespace Audit.Testing
{
    public partial class UploadTesting : System.Web.UI.Page
    {
  
          
        protected DataTable TheData
        {
            get
            {
                if (Session["TheData"] == null)
                {
                    DataTable dt = new DataTable();
                    DataColumn dcFilename = new DataColumn();
                    dcFilename.ColumnName = "Filename";
                    dcFilename.DataType = System.Type.GetType("System.String");
                    dt.Columns.Add(dcFilename);
                    DataColumn dcFiledata = new DataColumn();
                    dcFiledata.ColumnName = "FileData";
                    dcFiledata.DataType = typeof(byte[]);
                    dt.Columns.Add(dcFiledata); 
                            DataColumn dcId = new DataColumn(); 
                            dcId.ColumnName = "Id"; 
                            dcId.DataType = typeof(int); 
                            dt.Columns.Add(dcId);
  
                    Session["TheData"] = dt;
                }
                return (DataTable)Session["TheData"];
                  
            }
            set
            {
                Session["TheData"] = value;
            }
        }
  
        public string GetApplicationPath()
        {
            IMSCommonLibrary.Utilities.Objects.Globals gb = new IMSCommonLibrary.Utilities.Objects.Globals();
            return gb.Get_Server_Prefix();
        }
  
        protected void Page_Load(object sender, EventArgs e)
        {
  
        }
  
        protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = TheData;
        }
  
        protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem gei = e.Item as GridEditableItem;
                ((RadUpload)gei.FindControl("FileUploader")).OnClientFileSelected = "uploadFileSelected";
            }
        }
  
        protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
        {
  
        }
    }
}

Can anyone steer me in the right direction here?  I have had no success with the GridAttachmentColumn either, so please give feedback to my design as stated.  I am not able to use SQLDataSource controls for this purpose, with datasets/datatables being my only communications with the data-layer/db.
Thanks,
Steele.

*Edit* Telerik version is 2010.3.1109.40

4 Answers, 1 is accepted

Sort by
0
Steele
Top achievements
Rank 1
answered on 12 Dec 2010, 11:52 AM
Hi,
Any help on this?
I would like to add that a RadUpload control works fine on it's own, so it's with the intergration with the grid that I am having issue.
Thanks,
Steele.
0
Steele
Top achievements
Rank 1
answered on 12 Dec 2010, 11:53 AM
** Removed double post from server error **
0
Nikolay Rusev
Telerik team
answered on 16 Dec 2010, 09:12 AM
Hello Steele,

I suspect that the issue is caused due to eventArgs.EnableAjax = false; it should be eventArgs.set_enableAjax(false); as in the demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/gridattachmentcolumn/defaultcs.aspx

Please give it a try and let me know how it goes.

Greetings,
Nikolay
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Steele
Top achievements
Rank 1
answered on 17 Dec 2010, 12:27 AM
Hi Nikolay,
I have just "solved" this issue.
The code I have used EnableAjax was ripped straight from an example in response to someone elses query on the forums - I had tried the way your proposed before with no luck.
I am not sure what was the issue in the end.  After confirming the issue on another machine, I reinstalled Telerik and re-created the page from scratch.  Things started to work as expected from then on.
Thanks for checking this out.  Uploading with business rules seems very complicated for a seemingly simple action. :)
Tags
Grid
Asked by
Steele
Top achievements
Rank 1
Answers by
Steele
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or