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

FileUpload Control in UserControl with RadGrid

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
darenkov
Top achievements
Rank 1
darenkov asked on 04 Oct 2009, 02:05 PM
I want to use a fileupload control in an editable WebUserControl in conjunction with a RadGrid.

I have put everything together, but when I try to upload the file it says.

Index was out of range. Must be non-negative and less than the size of the collection.

This is strange because when copy and paste the code in non-user control (regular aspx page), it works fine.  I have tried the code in the WebUserControl which is called by the RadGrid Parent page, and I have also tried referencing the WebUserControl from within the Parent page, yet the message is the same either way.

Here is the code on my Parent RadGrid page which calls the UserControl with the FileUpload control in it:

protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    { 
        GridEditableItem editedItem = e.Item as GridEditableItem; 
        UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); 
 
        RadUpload RadUpload1 = userControl.FindControl("RadUpload1"as RadUpload; 
        Repeater repeaterResults = userControl.FindControl("repeaterResults"as Repeater; 
        Label labelNoResults = userControl.FindControl("labelNoResults"as Label; 
 
        string targetFolder = Server.MapPath(RadUpload1.TargetFolder); 
 
        UploadedFile file = RadUpload1.UploadedFiles[0]; 
        string uniqueFileName = System.Guid.NewGuid().ToString(); 
        string targetFileName = Path.Combine(Server.MapPath("~/shared/videos/members"), uniqueFileName + file.GetExtension()); 
        file.SaveAs(targetFileName); 
        //delete unique filename if database insert fails         
 
        if (RadUpload1.UploadedFiles.Count > 0) 
        { 
            repeaterResults.DataSource = RadUpload1.UploadedFiles; 
            repeaterResults.DataBind(); 
            labelNoResults.Visible = false
            repeaterResults.Visible = true
        } 
        else 
        { 
            labelNoResults.Visible = true
            repeaterResults.Visible = false
        } 

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 07 Oct 2009, 10:36 AM
Hello darenkov,

Could you please specify if the grid is ajaxified?
Please note that you nned to disable ajax when uploading files as it is done here and described in this help topic.

Check it out and let me know how it goes.

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
darenkov
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or