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

RadAsyncUpload unable to persist data for asp:Repeater

5 Answers 92 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Benjamin
Top achievements
Rank 1
Benjamin asked on 18 Nov 2016, 06:13 AM

Hi. i am trying to form for user to type in the name of their course. then each of this course will be able to upload multiple files. 

for example user type Computer Engineering, then they are able to upload multiple files for this Computer Engineering. i have tried to do a sample test page to try out the control. but when i click on the Add to add a row to repeater, the previously uploaded data got lost.

 

Markup:

01.<asp:UpdatePanel ID="pnlEntryTemplate1" runat="server" UpdateMode="Conditional">
02.    <ContentTemplate>
03.        <asp:Repeater ID="rptReplyDate" runat="server" OnItemCommand="rptReplyDate_ItemCommand">
04.            <HeaderTemplate>
05.                <table cellpadding="0px" cellspacing="0px">
06.            </HeaderTemplate>
07.            <FooterTemplate>
08.                    <tr>
09.                        <td style="padding: 1em 1em;" align="right">
10.                            <asp:Button ID="btnAddEntry" runat="server" Text="Add Entry" OnClick="btnAddEntry_Click" />
11.                        </td>
12.                    </tr>
13.                </table>
14.            </FooterTemplate>
15.            <ItemTemplate>
16.                <tr>
17.                    <td style="padding: 1em 1em;">
18.                        <table cellpadding="0px" cellspacing="0px" class="repeaterTable">
19.                            <tr>
20.                                <td>
21.                                    <asp:TextBox ID="txtName" ClientIDMode="Static" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "txtName") %>'></asp:TextBox>
22.                                </td>
23.                            </tr>
24.                            <tr>
25.                                <td>
26.                                    <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" PostbackTriggers="btn_Submit"></telerik:RadAsyncUpload>
27.                                </td>
28.                            </tr>
29.                        </table>
30.                    </td>
31.                </tr>
32.            </ItemTemplate>
33.        </asp:Repeater>
34.    </ContentTemplate>
35.</asp:UpdatePanel>
36.<asp:Button ID="btn_Submit" runat="server" Text="Submit" OnClick="btn_Submit_Click" />

5 Answers, 1 is accepted

Sort by
0
Benjamin
Top achievements
Rank 1
answered on 18 Nov 2016, 07:34 AM

i understand that when i add the control the repeater rebind. so now how do i set back the files back to the asyncupload control

 

current code when btn_add is click to add the row

01.protected void btnAddEntry_Click(object sender, EventArgs e)
02.{
03.    List<ReplayDate> col = new List<ReplayDate>();
04.     foreach(RepeaterItem item in rptReplyDate.Items)
05.     {
06.            ReplayDate data = new ReplayDate();
07.            data.txtName = ((TextBox)item.FindControl("txtName")).Text;
08.            data.files = ((RadAsyncUpload)item.FindControl("RadAsyncUpload1")).UploadedFiles;
09.            col.Add(data);
10.     }
11.     ReplayDate newData = new ReplayDate();
12.     rptReplyDate.DataSource = col;
13.     rptReplyDate.DataBind();
14.}
15. 
16.public class ReplayDate
17.{
18.    public int id { get; set; }
19.    public string txtName { get; set; }
20.    public UploadedFileCollection files { get; set; }
21.}
0
Veselin Tsvetanov
Telerik team
answered on 18 Nov 2016, 11:12 AM
Hi Benjamin,

I am afraid that you won't be able to repopulate the RadAsyncUpload control after the Repeater control has been rebound. To achieve the desired functionality, I would suggest you not to use Repeater, but a simple Panel control and append the newly added controls to its controls collection.

Regards,
Veselin Tsvetanov
Telerik by Progress
Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
0
Benjamin
Top achievements
Rank 1
answered on 18 Nov 2016, 03:08 PM
Hi Veselin. thanks for the reply. as this is my 1st time adding dynamic control without using asp:Repeater. it is possible for u to provide some simple sample code or demo to refer to?
0
Veselin Tsvetanov
Telerik team
answered on 23 Nov 2016, 12:56 PM
Hello Benjamin,

I would suggest you to review the following MSDN article demonstrating how to add controls from the code behind to the Controls collection of a asp:Panel.

Note that you will have to add the newly created panel to an existing panel on the page:
PanelPlaceholder.Controls.Add(Panel1);

Regards,
Veselin Tsvetanov
Telerik by Progress
Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
0
roshan
Top achievements
Rank 1
answered on 09 Mar 2018, 03:43 PM

In repeater,when you submit the file.The page is posted back to server so that repeater is rebind .Hence it lose its value.

so it's better to use  "isPostBack " in your page load event.

Use  

 protected void Page_Load(object sender, EventArgs e)
    {    
        if(!IsPostBack)
        {

    }
    }

Tags
AsyncUpload
Asked by
Benjamin
Top achievements
Rank 1
Answers by
Benjamin
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
roshan
Top achievements
Rank 1
Share this question
or