Persist Uploaded Files with autogenerated PerformInsertButton on Radgrid

2 posts, 0 answers
  1. Michael
    Michael avatar
    10 posts
    Member since:
    Jan 2013

    Posted 30 May 2013 Link to this post

    Perhaps someone can help with this.

    I'm currently trying to upload some files to be inserted into a db table.  The files are linked to a parent record id in a different table.

    Appointment <= (Many) Attachments

    So one appointment can have many attachments.

    Within a radgrid the user enters details for a new appointment and can then upload attachment files.  The attachment files are to be inserted  with the new appointment record id.

    The problem I have found is that the File Upload triggers before the insert of the new record (which is inserted using an entitydatasource).

    My thinking is that if I can capture the insert of the record and use PostbackTriggers, I can insert the new appointment, capture the newly generated appointment id, then trigger the upload of the files which will now be able to be inserted with the appointment id.

    If anyone could point me to an example where you can capture the PerformInsertButton button click on the insert form and then trigger the upload in this order it would be considerable help at the moment.

    The nearest example code I can find for what I want to do seems to be Scotts code in this post :

    http://www.telerik.com/community/forums/aspnet-ajax/async-upload/retain-uploaded-files-for-display-after-postback.aspx

    Thanks.
  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 04 Jun 2013 Link to this post

    Hi Michael,

    Once the ItemCommand event is fired, you could use FindControl() to get instance of RadAsyncUpload from the Inserted form. Then get and save file you need from the UploadedFiles collection:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.PerformInsertCommandName)
        {
            GridEditFormItem insertItem = (GridEditFormItem)e.Item;          
            RadAsyncUpload upload =(RadAsyncUpload) insertItem.FindControl("RadAsyncUpload1");
            string path = Server.MapPath("~/Uploads/");
            string fileName = upload.UploadedFiles[0].FileName;
            upload.UploadedFiles[0].SaveAs(path + fileName);
        }
    }

    Sample project is attached.

    Regards,
    Hristo Valyavicharski
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top