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

RadUpload in grid event doesn't work

7 Answers 115 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Silvio Silva Junior
Top achievements
Rank 2
Silvio Silva Junior asked on 22 Apr 2010, 07:17 PM
Hello Guys.

I have a radupload in a grid, and when I try to get the file name in grid's insert command, I have no uploaded files in RadUpload control.

Look my snipet code:

GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item; 
        RadUpload RadUpload1 = (insertedItem["myItem"].Controls[1] as RadUpload); 
 
        for (int i = 0; i <= RadUpload1.UploadedFiles.Count; i++) 
        { 
            string fileName = RadUpload1.UploadedFiles[i].FileName; 
        } 

What can I do?

Regards.

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Apr 2010, 08:42 AM
Hello Silvio,

RadUpload needs full postbacks to upload the files on the server. If you have ajaxified your RadGrid, you will need to temporarily disable AJAX for your RadGrid during uploading.

Checkout the demo for more information on the topic:
Using RadUpload in ajaxified RadGrid


-Shinu.
0
Silvio Silva Junior
Top achievements
Rank 2
answered on 23 Apr 2010, 03:42 PM
Hi Shinu, and thanks for the answer bro.

My problem is, I don't have a GridBinaryImageColumn in my grid. I have a template column:

<telerik:GridTemplateColumn HeaderText="Image" UniqueName="IdImage" DataField="IdImage" DataType="System.String" ItemStyle-Width="60px">     
                            <EditItemTemplate>    
                                <telerik:RadUpload ID="RadUpload1" runat="server" TargetFolder="../content/images/" ControlObjectsVisibility="None">     
                                </telerik:RadUpload>    
                            </EditItemTemplate>    
    
                            <ItemTemplate>    
                                <asp:Image runat="server" ID="img"      
                                    ImageUrl='<%# Bind("idi_str_path_icon") %>' Width="16px" Height="16px" />    
                            </ItemTemplate>    
                            <ItemStyle Width="60px" />    
                        </telerik:GridTemplateColumn>    
 

so, I can't use this:

RadAjaxPanel1.ResponseScripts.Add(string.Format("window['UploadId'] = '{0}';", editor.RadUploadControl.ClientID)); 

I tryed that:
RadUpload ru = (RadUpload)item["idi_str_path_icon"].Controls[1];  
RadAjaxPanelIdioma.ResponseScripts.Add(string.Format("window['UploadId'] = '{0}';", ru)); 

But I got a error in this line:
if (upload.getFileInputs()[0].value != "") {     
                eventArgs.set_enableAjax(false);     
            }
 

saying: Runtime Error in Microsoft JScript: 'null' is null or not an object.

So, what can I do to use the Radupload in template column?
0
Genady Sergeev
Telerik team
answered on 26 Apr 2010, 09:32 AM
Hi Silvio Silva Junior,

You can use the following code for RadUpload that is inside a template column.

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       {
           RadUpload upload = (RadUpload)e.Item.FindControl("RadUpload1");
           RadAjaxPanel1.ResponseScripts.Add(string.Format("window['UploadId'] = '{0}';", upload.ClientID));
           
       }
   }


Kind regards,
Genady Sergeev
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Silvio Silva Junior
Top achievements
Rank 2
answered on 29 Apr 2010, 09:05 PM
Hello.

Ok Genady Sergeev, but, in InsertCommand, how can I get the RadUploadControl with uploaded files?

Look at this:

RadUpload ru = (insertedItem["ColumnName"].Controls[1] as RadUpload);

But, this object have no UploadedFiles.

What's wrong?



0
Genady Sergeev
Telerik team
answered on 04 May 2010, 12:50 PM
Hello Silvio Silva Junior,

I suppose that you haven't disabled the ajax functionality when uploading files. As Shinu has mentioned, please apply the workaround listed here. Since you can now access the RadUpload from the codebehind there should be no problem when applying the workaround.

Best wishes,
Genady Sergeev
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Larry
Top achievements
Rank 1
answered on 01 Aug 2010, 08:07 PM
Prepending RUC_ to the UniqueName of your GridBinaryImageColumn works for me.
I was just battling with this myself and did a view source on the page and found what I needed.  So my RadGrid1_InsertCommand contains:
    RadUpload uplPhoto = (RadUpload)e.Item.FindControl("RUC_Attachment1");
for my column:
<telerik:GridBinaryImageColumn DataAlternateTextField="Comment" DataField="Attachment1" HeaderText="Attachments" ImageHeight="40" ImageWidth="40" UniqueName="Attachment1">
</telerik:GridBinaryImageColumn>

I hope this helps!
0
Larry
Top achievements
Rank 1
answered on 01 Aug 2010, 08:52 PM
Some more playing around found that I could also get the same results with the following snippit:

RadUpload uplPhoto = (RadUpload)insertedItem["Attachment1"].Controls[0];

 so it looks like your Controls[1] may have been the source of your problem all along?
Tags
Upload (Obsolete)
Asked by
Silvio Silva Junior
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Silvio Silva Junior
Top achievements
Rank 2
Genady Sergeev
Telerik team
Larry
Top achievements
Rank 1
Share this question
or