0

I know there are lots of examples and samples of code to upload the file asynchronously, but unfortunately no one is working for me.

I placed the update panel but File Uploader doesn't work in update panel. I have 4 text fields and a file uploader on the page. I want to save all information and want to upload file without any postback.

I saw AjaxFileUpload control of ajax control toolkit but it uploads the file instantly when we select it. But i want to upload the file on click of the button.

Please let me know any one has solution for it.

Thanks

2 Answers 2

1

The Ajax Control Toolkit you mentioned as an AjaxFileUpload that you can use. And yes, it can be hooked up to a button as demonstrated in the page I linked to. Please use it and then let us know specifically what problems you run into with it.

Sign up to request clarification or add additional context in comments.

1 Comment

I saw this link as well. The upload button is with the ajax control. I can't use separate button to upload the files.
0

I was just having the same problem. All the examples I saw online did not work for me either. After stripping down the code, I figured I had to use ToolKitScriptManager and not the standard asp:ScriptManager.
I have not use the the toolkit before so I don't know if this is a new requirement with the latest toolkit since all the older examples I read used the ScriptManager and said it is supposed to work fine.

Here is the code behind to save from a button click:

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    AjaxControlToolkit.AsyncFileUpload afu = (AjaxControlToolkit.AsyncFileUpload)sender;

    if (afu.HasFile)
    {
        Session["AsyncFileUploadImage"] = afu;
    }

}
protected void AsyncFileUpload1_UploadedFileError(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    ...
}
protected void btnSave_Click(object sender, EventArgs e)
{       
    if (Session["AsyncFileUploadImage"] != null)
    {
        this.AsyncFileUpload1 = (AjaxControlToolkit.AsyncFileUpload)Session["AsyncFileUploadImage"];
        this.AsyncFileUpload1.SaveAs(Path.Combine(Request.PhysicalApplicationPath,"images", "uploads", this.AsyncFileUpload1.FileName)); //make sure to save in directory with write permissions
        this.lblStatus.Text = "You uploaded " + AsyncFileUpload1.FileName;
    }
    else
    {
      ...
    }


}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.