RadUpload in grid event doesn't work

Thread is closed for posting
8 posts, 0 answers
  1. Silvio Silva Junior
    Silvio Silva Junior avatar
    100 posts
    Member since:
    Mar 2010

    Posted 22 Apr 2010 Link to this post

    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.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Apr 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Silvio Silva Junior
    Silvio Silva Junior avatar
    100 posts
    Member since:
    Mar 2010

    Posted 23 Apr 2010 Link to this post

    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?
  5. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 26 Apr 2010 Link to this post

    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.
  6. Silvio Silva Junior
    Silvio Silva Junior avatar
    100 posts
    Member since:
    Mar 2010

    Posted 29 Apr 2010 Link to this post

    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?



  7. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 04 May 2010 Link to this post

    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.
  8. Larry
    Larry avatar
    3 posts
    Member since:
    Oct 2008

    Posted 01 Aug 2010 Link to this post

    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!
  9. Larry
    Larry avatar
    3 posts
    Member since:
    Oct 2008

    Posted 01 Aug 2010 Link to this post

    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?
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017