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 :
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 :
Code behind :
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
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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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