0

I have an asyncfileupload control and a repeater that I would like to use to show list of added files. On FileUploadedComplete event I add the new file's name and size to a data table and use it to bind the repeater. I can select a file and add it (SaveAs()), add the info to data table (I can see it is there) but after calling repeater's databind() nothing happens, can't see the file data. This is what I have (watered down version):

<asp:UpdatePanel runat="server" ID="upnlFU">
    <ContentTemplate>
        <ajaxToolkit:AsyncFileUpload
            runat="server"
            ID="fuAttchedDocs" 
            ThrobberID="myThrobber" 
            UploaderStyle="Modern"
            onuploadedcomplete="fuAttchedDocs_UploadedComplete" 
            onuploadedfileerror="fuAttchedDocs_UploadedFileError" />

        <asp:Repeater runat="server" ID="rptAttachments">
            <HeaderTemplate>
                <table>
                    <tr>
                        <td>File Name</td>
                        <td>File Size</td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td><%# Eval("FileName")%></td>
                    <td><%# Eval("FileSize")%></td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>
    </ContentTemplate>
</asp:UpdatePanel>

Code behind:

DataTable dtAttachments;

protected void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)
    {
        dtAttachments = new DataTable();
        dtAttachments.Columns.Add("FileName", Type.GetType("System.String"));
        dtAttachments.Columns.Add("FileSize", Type.GetType("System.Int32"));
        dtAttachments.AcceptChanges();
    }
    else
    {
        dtAttachments = (DataTable)ViewState["Attachments"];
    }
    BindAndSaveAttachmentData();
}

void BindAndSaveAttachmentData()
{
    ViewState["Attachments"] = dtAttachments;
    rptAttachments.DataSource = dtAttachments;
    rptAttachments.DataBind();
}

protected void fuAttchedDocs_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
    string sFileName = fuAttchedDocs.FileName;
    string sFileSize = e.FileSize;
    fuAttchedDocs.SaveAs(FilePath.TEMP_FOLDER + sFileName); // Saving to d:\blah\yada temporary folder
    dtAttachments.Rows.Add(new object[] { sFileName, int.Parse(sFileSize) });
    BindAndSaveAttachmentData();
}

Both file upload and repeater are inside an update panel.

NoBullMan
  • 2,032
  • 5
  • 40
  • 93
  • update post to include update panel tags – NoBullMan Mar 11 '14 at 20:10
  • Put the Async File Upload control in one update panel, put the repeater in another update panel. The on client side event of upload Complete (i.e. onClientUploadComplete), do a __doPostBack('update_panel_id_of_repeater'). – NoBullMan Mar 13 '14 at 15:23

0 Answers0