简体   繁体   中英

How do I prevent the AsyncFileUpload from sending the file again on postback?

I am developing an application that manages a photo contest. In that application, I use an AsyncFileUpload control for the user selected photo. The server-side UploadedComplete does basic validation, and scales/clip the image as necessary.

The problem is, when i click on the submit button on the page, the content of the AsyncFileUpload gets sent with the other user-submitted data, so the user gets to wait twice as long to get a response from the server (I'm expecting photos that are between 3 and 7 Mb big, which takes a minute or two to upload).

My form looks like that:

<%-- ... snip - all other fields ... -->
<div style="margin-top: 20px; margin-bottom: 5px;">
    <span class="texteB"><b>Upload a photo</b></span><br />
    Browse your computer to find a photo.</div>
<div>
    <asp:AsyncFileUpload onclientuploaderror="UploadError" persistfile="true" onuploadedcomplete="fuPhoto_UploadedComplete"
        completebackcolor="#52ad0b" onclientuploadstarted="UploadStarted" id="fuPhoto"
        throbberid="throbber" runat="server" />
</div>
<div runat="server" id="throbber" style="display: none; margin: 8px 0 15px 0">
    <div style="float: left; width: 48px;">
        <img src="images/throbber.gif" /></div>
    <span class="texteV_14pt"><b>Please wait while
        <br />
        your photo is uploaded...</b></span>
</div>
<div style="margin-top: 20px; margin-bottom: 20px;">
    Please double-check your informations and press Send when ready.</div>
<div>
    <asp:ImageButton onclick="btnSubmit_Click" ImageUrl="images/bt_envoyer_demande.gif"
        runat="server" id="btnSubmit" />
</div>

Is there something I missed out in the documentation? I've been working on this all day without much success.

Thanks in advance!

The AsyncFileUpload doesn't really work like this. It only really works when you use the filedata in the OnUploadedComplete event.

I'd just bite the bullet and use something like SWFUpload or just use a native FileUpload control.

private bool _justDeleted = false;

void AsyncFileUpload1_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
    if (_justDeleted) return;

protected void btnDeleteLogo_Click(object sender, EventArgs e)
{
    _justDeleted = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM