Problem with loss of file references in RadAsynceUpload

5 posts, 0 answers
  1. Boris
    Boris avatar
    276 posts
    Member since:
    Oct 2012

    Posted 14 Oct 2014 Link to this post

    I've only recently replaced the RadUpload controls in my web app with RadAsyncUploads.  By and large they're working OK.

    In the postback event I grab a reference to the uploaded file ( UploadedFile file = RadUpload1.UploadedFiles[0]; ) and process it.

    There's one small problem.  The page the upload control is on also has several custom validators that do server-side validation.  If one of these validators fires the file reference in the RadAsyncUpload control is wiped and it is necessary to select the file again. 

    Am I forgetting something basic?  
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 16 Oct 2014 Link to this post

    Hello,

    I assume that a button will initiate a post-back to the server in order to validate the user input. The RadAsyncUpload PostbackTriggers property contains the control ids that will fire the RadAsyncUpload FileUploaded server-side event and move the file from the temp folder to the target folder.

    So basically if you have a RadButton set as a post-back trigger for the RadAsyncUpload and hide it the other button will not submit the files but will make a post-back in order to execute your custom validation.
    //markup code
    <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" PostbackTriggers="RadButton1"></telerik:RadAsyncUpload>
                <telerik:RadButton AutoPostBack="true" runat="server" ID="RadButton1" Visible="false"></telerik:RadButton>
                <telerik:RadButton AutoPostBack="true" runat="server" ID="RadButton2"></telerik:RadButton>



    Regards,
    Boyan Dimitrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Boris
    Boris avatar
    276 posts
    Member since:
    Oct 2012

    Posted 16 Oct 2014 in reply to Boyan Dimitrov Link to this post

    I'm afraid I'm still lost.  If I set up the controls like you suggest, the AsyncUpload control seems to retain it's setting (file name is still visible) but after I correct the server-side validation and hit the save button again, the UploadedFiles property is still empty.
  5. Boris
    Boris avatar
    276 posts
    Member since:
    Oct 2012

    Posted 16 Oct 2014 Link to this post

    Let me elaborate a bit more.  If the Save button is clicked and the save routine is run, the uploaded file is handled like this:

      if (RadUpload1.UploadedFiles.Count > 0)              
      {
           UploadedFile file = RadUpload1.UploadedFiles[0];                    
           byte[] bytes = new byte[file.ContentLength];
           file.InputStream.Read(bytes, 0, (int)file.ContentLength);
           ...  At this point the file is inserted into a record field, and then the record itself is saved,  etc.


    Am I going about this all wrong?
  6. Boris
    Boris avatar
    276 posts
    Member since:
    Oct 2012

    Posted 20 Oct 2014 Link to this post

    Let's close this.  I found an alternative.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017