How to use AsyncFileUpload in ajax

AsyncFileUpload in ajax
AsyncFileUpload is an ajax control. AsyncFileUpload control allow us to asynchronously upload files to web server. this control provide a way to check file uploading results both in the server side and client side.

AsyncFileUpload control have the following useful properties those are CompleteBackColor, ContentType, ErrorBackColor, FileContent, FileName, HasFile, OnClientUploadComplete, OnClientUploadError, OnClientUploadStarted, PostedFile, ThrobberID, UploaderStyle, UploadingBackColor, and Width.

AsyncFileUpload ajax control CompleteBackColor property value is a color name which color show as AsyncFileUpload control's background color when upload complete. ErrorBackColor property set a color name which color display as control's background color when file upload occurs an error. UploadingBackColor property assign a color name which color show as control's background color when file upload is in progress.

AsyncFileUpload control's ContentType property get the MIME content type of a file which file sent by a client browser. FileName property get the client uploaded file name. HasFile property indicate whether AsyncFileUpload control contains a file. FileContent property gets a stream object of client uploaded file. PostedFile property get a HttpPostedFile object that allow access to the uploaded file.

AsyncFileUpload control's each OnClientUploadStarted, OnClientUploadError and OnClientUploadComplete property set a javascript function name that can be executed in the client side. OnClientUploadStarted specified javascript function executed when file uploading started. OnClientUploadError specified function executed when file upload failed. when file upload complete then the OnClientUploadComplete property specified javascript function executed on client side.

AsyncFileUpload control's UploaderStyle property have two possible values those are Traditional and Modern. this property change the appearance (look and feel) of AsyncFileUpload control.

AsyncFileUpload control provides two events those are UploadedComplete and UploadedFileError. AsyncFileUpload control's UploadedFileError event fired when uploaded file is corrupted. UploadedComplete event fire when file successfully uploaded. both event fired on server side.

AsyncFileUpload ajax control also provide a method named SaveAs. this method require a string argument which ask a filename. SaveAs method allow us to save the contents of an uploaded file.

<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!DOCTYPE html>

<script runat="server">
    protected void UploadComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
        string filePath = Request.PhysicalApplicationPath+ "Image\\" + AsyncFileUpload1.PostedFile.FileName;
<script type="text/javascript">
    function showConfirmation() {
        document.getElementById('Label1').innerText = 'upload complete.';

<html xmlns="" >
<head id="Head1" runat="server">
    <title>How to use AsyncFileUpload in ajax</title>
    <form id="form1" runat="server">
        <h2 style="color:OrangeRed; font-style:italic;">Ajax AsyncFileUpload Example: How To Use AsyncFileUpload</h2>
        <hr width="650" align="left" color="salmon" />
        <br />            
Related ajax examples