Net-informations.com
SiteMap  | About    

Ajax AsyncFileUpload Control

Ajax introduces a new approach to WebPages that update the portion of a the page by a techniques called Partial-page rendering. The Ajax Control Toolkit contains controls that you can use to build highly responsive and interactive Ajax-enabled Web applications. AsyncFileUpload is an ASP.NET AJAX Control that allows you asynchronously upload files to server, it uploads the file without any postback. The file uploading results can be checked both in the server and client sides.

ajax-file-upload

You can show the loading image while file uploading is in progress. Also you can save the uploaded file by calling the SaveAs() method in a handler for the server UploadedComplete event.

C#
  if (AsyncFileUpload1.HasFile)
  {
	AsyncFileUpload1.SaveAs(@"C:\upload\" + AsyncFileUpload1.FileName);

}

vb.net
  If AsyncFileUpload1.HasFile Then
	AsyncFileUpload1.SaveAs("C:\upload\" + AsyncFileUpload1.FileName)

End If

The following Asp.Net Ajax program shows how to integrate an AsyncFileUpload to your web application. To use the Ajax Control Toolkit in your Visual Studio project, you should add reference to the AjaxControlToolkit.dll in your project.

Default.aspx

  

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>Untitled Page</title>
	<script type="text/javascript">
		function clientMessage() {
		document.getElementById("Label1").innerHTML = "File Uploaded Completed ";
		}
	</script>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:ScriptManager ID="sm1" runat="server" />
		<cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server"
		UploadingBackColor="#82CAFA"
		CompleteBackColor = "#FFFFFF"
		OnUploadedComplete="doUpload"
		OnClientUploadComplete="clientMessage"
		ThrobberID="Throbber"  />
		<asp:Image ID="Throbber" runat="server"
		ImageUrl = "http://asp.net-informations.com/ajax/img/throbber.gif" />
		<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
		<br />
	</div>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
Default.aspx.cs
Default.aspx.vb





net-informations.com (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.