UploadedFiles returns 0 files

6 posts, 0 answers
  1. TelDev
    TelDev avatar
    32 posts
    Member since:
    Dec 2009

    Posted 22 Nov 2013 Link to this post

    Hi,

    I am using asyncupload for storing files into database.

    I have 2 grids and a upload control and a save to database button. The selection of a row from 1st grid selects rows from 2nd grid. After this, a file is uploaded using asyncupload. Now by clicking the submit button I want to save the grid selections and the file to database.
    I have attached a PostbackTriggers property to asyncupload  control because when i upload a file and change the selection in first grid the file is gone because of postback. If i remove PostbackTriggers property UploadedFiles count is not zero.

    The UploadedFiles of asyncupload is always returning 0 files when i use PostbackTriggers.
    I have attached an image to describe the controls.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Nov 2013 Link to this post

    Hi TelDev,

    Please have a look into the following code snippet to get the count of UploadedFiles of RadAsyncUpload.

    ASPX:
    <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" PostbackTriggers="RadButton1"
        OnFileUploaded="RadAsyncUpload1_FileUploaded">
    </telerik:RadAsyncUpload>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Save UploadedFile">
    </telerik:RadButton>
    <telerik:RadButton ID="RadButton2" runat="server" Text="Page PostBack">
    </telerik:RadButton>

    C#:
    protected void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
    {
        // when RadButton1 Click is happening this event will execute
        int count = RadAsyncUpload1.UploadedFiles.Count;
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. TelDev
    TelDev avatar
    32 posts
    Member since:
    Dec 2009

    Posted 25 Nov 2013 Link to this post

    Thanks Shinu for the reply,

    I need UploadedFiles in some button event, but not in  RadAsyncUpload1_FileUploaded.
    As you see in my attached image, I need the UploadedFiles count and the file in "Apply" button click.

    Thanks
    TelDev
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Nov 2013 Link to this post

    Hi TelDev,

    Please have a look into the following code snippet to get the count and file name of the uploaded file in RadButton OnClick event.

    ASPX:
    <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" PostbackTriggers="RadButton1">
    </telerik:RadAsyncUpload>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Apply" OnClick="RadButton1_Click">
    </telerik:RadButton>
    <telerik:RadButton ID="RadButton2" runat="server" Text="Page PostBack">
    </telerik:RadButton>

    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        string[] uplodedfile = new string[20];
        //count of the uploaded file
        int count = RadAsyncUpload1.UploadedFiles.Count;
        int i=0;
        foreach (UploadedFile file in RadAsyncUpload1.UploadedFiles)
        {
            //filename of the uploaded file
            uplodedfile[i] = file.FileName;
            i++;
        }
    }

    Thanks,
    Shinu.
  6. TelDev
    TelDev avatar
    32 posts
    Member since:
    Dec 2009

    Posted 26 Nov 2013 Link to this post

    Thank you again Shinu,

    My case is bit different. If you see the attached image I have 2 grids and a upload control. I need a postbacktrigger for grid1 and also apply button.

    Can I use 2 controls for postbacktriggers property?

    I have found the documentation, it seems I can set multiple controls.

    http://www.telerik.com/help/aspnet-ajax/asyncupload-persist-uploaded-files.html

    Thanks
    TelDev
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 27 Nov 2013 Link to this post

    Hi TelDev,

    It is possible to set more than one control in the PostbackTriggers property of RadAsyncUpload. Please have a look into the following code snippet to set two controls in PostbackTriggers property.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" AllowPaging="true" runat="server" DataSourceID="SqlDataSource1"
        AutoGenerateColumns="true">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn HeaderText="OrderID" DataField="OrderID" UniqueName="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="CustomerID" DataField="CustomerID" UniqueName="CustomerID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="ShipName" DataField="ShipName" UniqueName="ShipName">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Apply" OnClick="RadButton1_Click">
    </telerik:RadButton>
    <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" PostbackTriggers="RadButton1,RadGrid1">
    </telerik:RadAsyncUpload>

    Thanks,
    Shinu.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017