14

Closed

AsyncFileUpload and UpdatePanels

description

2 problems here with UpdatePanels
first is that it's impossible to cause a postback from the UploadedComplete (whats up with that name?) handler. I've been able to hack the AsyncFileUpload to do an UpdatePanel postback by using a hidden button and triggering the click event to cause the postback. But when the UpdatePanel refreshes, the AsyncFileUpload control is broken (either invisible or something like "32442--------image/jpg")

second is that if you have an upload in progress, and someone clicks a button to cause a partial postback, the client is nice enough to wait for the upload to complete, but the AFU is replaced by the same string of meaningless text (as above). (replace the ScriptManager line below with a Timer.Sleep(2000) to see this behavior) If the user dosn't cause a postback durring upload, the UpdatePanel and AFU seem to refresh and continue to function as they should.

codebehind:
protected void AsyncFileUpload1_UploadedComplete(object sender, AsyncFileUploadEventArgs e) {
    //For Auto-Postback
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "reply", "top.$get(\"" + btnUploadComplete.ClientID + "\").click();", true);
    //here's an upload delay
    System.Threading.Thread.Sleep(2000);
}

protected void btnUploadComplete_Click(object sender, EventArgs e) {
    lbl.Text = "File Recieved: " + AsyncFileUpload1.FileName;
}
and the HTML
    <asp:UpdatePanel runat="server" ID="updatePanel" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnUploadComplete" EventName="Click" />
        </Triggers>
        <ContentTemplate>
            <ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" runat="server" 
                OnUploadedComplete="AsyncFileUpload1_UploadedComplete" ThrobberID="throbber"/>
            <asp:Image runat="server" ID="throbber" ImageUrl="~/images/throbber.1.gif" />
            <asp:Button runat="server" ID="btnUploadComplete" Text="Done Uploading" OnClick="btnUploadComplete_Click" />
            <asp:Label runat="server" ID="lbl" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload2" runat="server" style="display:none;"/>
Closed Jul 23 at 10:13 AM by MikhailTymchukDX

comments

brianhevans wrote Jun 3, 2010 at 2:07 PM

This creates a PostBack but I am not actually seeing my UpdatePanel, which contains a grid. Any ideas why?

MikhailTymchukDX wrote Jul 16 at 2:37 PM

We were unable to reproduce this issue with the latest version of the AJAX Control Toolkit.
Would you provide a sample project that uses AJAX Control Toolkit v15.1?