Hi
I was created one web application. In which i am using the ajax control asyncfileupload file uploader in update panel.
Upload file correctly but when i refresh the page then double this file is uploaded..
how to fix this problem in asp.net? please help me
how to postback the page..

Dani AI

Generated

Two likely causes — and simple fixes — for the behavior you describe (file uploads twice after a refresh):

  • Either the browser is re‑submitting a POST when the page is refreshed (the classic double-submit problem), or the AsyncFileUpload flow is actually performing two uploads: the control’s async upload, then your page code (or a forced postback such as a client __doPostBack) is re‑running the same save logic. and were right to suggest guarding Page_Load when you put save logic there, but when you use AjaxControlToolkit’s AsyncFileUpload the reliable place to persist the file is the control’s server UploadedComplete handler — and be aware UpdatePanel/partial-postback interactions can complicate file-upload flows. (ajaxcontroltoolkit6.rssing.com)

Move the save to UploadedComplete and add a small server-side dedupe check. Example (C#):

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    // quick dedupe fingerprint (name + length). Use DB or persistent token for stronger guarantees.
    string fingerprint = e.FileName + "|" + AsyncFileUpload1.PostedFile.ContentLength;
    if (Session["LastUploadFingerprint"] != null &&
        Session["LastUploadFingerprint"].ToString() == fingerprint)
        return;
    Session["LastUploadFingerprint"] = fingerprint;

    string safeName = Path.GetFileName(e.FileName);
    string savePath = Server.MapPath("~/Uploads/") + Guid.NewGuid().ToString("N") + "_" + safeName;
    AsyncFileUpload1.SaveAs(savePath);
}

This keeps saving out of Page_Load and prevents a second save if the handler is triggered twice. The control exposes the usual server events and SaveAs() for persisting uploads. (ajaxcontroltoolkit6.rssing.com)

If the duplicate comes from refreshing the browser after a POST, break the POST chain (Post/Redirect/Get). With AsyncFileUpload you usually must do that on the client after the async upload completes (OnClientUploadComplete) because server-side Response.Redirect may only affect the upload iframe. Example client-side redirect:

<script type="text/javascript">
function onClientUploadComplete(sender, args) {
    // navigate to a GET result page or same page with a query flag to avoid re-submitting the POST
    window.location = window.location.pathname + "?uploaded=1";
}
</script>

PRG prevents the browser from resubmitting the POST on refresh. (en.wikipedia.org)

Troubleshooting checklist

  • Reproduce while watching Chrome/DevTools Network: are there two POST requests (two upload entries) or only one?
  • If you see two uploads immediately (not just after F5), search client scripts for doPostBack or a forced postback in OnClientUploadComplete — avoid forcing a raw doPostBack that causes the control to resend.
  • Add server logging (timestamp + Request headers) inside UploadedComplete to see how/when the handler runs.
  • As a last line of defense, deduplicate by filename+size/timestamp or use GUID prefixes when saving.

References: AjaxControlToolkit AsyncFileUpload docs for events/properties and guidance, and Microsoft UpdatePanel notes on file-upload caveats. (ajaxcontroltoolkit6.rssing.com)

Recommended Answers

All 3 Replies

Hi,
With no code to go on I'm speculating but have you got the code to upload the file in the Page_Load method? if so, and you don't want the action repeated, you need to put the code inside of

if(!Page.IsPostBack) {
// your code
}

This means your code is only called the first time the page is loaded. Subsequent reloads (postbacks) skip the code.

Is that what you need?

Hi,

Hope the solution given in the following link will help you.

AsyncFileUpload postback causes double upload

Someone has reported the same issue in CodePlex site . But it is closed as the issue cannot be reproduced.

write condition if(!page.IsPostback) then "write you code " end if

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.