Tuesday 2 April 2013

AsyncFileUpload Control


Ajax (Asynchronous JavaScript and XML) is a new web development technique for interactive websites. With the help of AJAX we can develop web applications and retrieve a small amount of data from the web server. AJAX consists of a different type of technology.
  • JavaScript
  • XML
  • Asynchronous Call to the server
AsyncFileUpload Control
AsyncFileUpload is a new ASP.NET AJAX Control that allows you to asynchronously upload files to server. You don't need a separate upload button for this control. Add the AsyncFileUpload control and a label to the web form for the uploading and displaying of messages respectively. The file uploading results can be checked both in the server and client sides. You can save the uploaded file by calling the SaveAs() method in a handler for the server UploadedComplete event.
Property
  • OnClientUploadComplete
  • OnClientUploadError
  • UploaderStyle
  • CompleteBackColor
  • ThrobberID

Example

Code :
<title> My Ajax APPLICATION</title>  
  <script type = "text/javascript">    
    function uploadComplete(sender) {
            $get("<%=lblMesg.ClientID%>").innerHTML = "File Uploaded Successfully";
    }
    function uploadError(sender) {
            $get("<%=lblMesg.ClientID%>").innerHTML = "File upload failed.";}
    }
</script> 
   </head>  
  <body> 
   <form id="form1" runat="server" style="background-color: #453A42">   
 <asp:ScriptManager ID="ScriptManager1" runat="server">    </asp:ScriptManager> 
 <p style="background-color: #FF8080"> ASYNC FILE UPLOAD CONTROL IN AJAX</p>    <br />  
  <div style="background-color: #8C7384">
 <asp:UpdatePanel ID="UpdatePanel1"runat="server">       
 <ContentTemplate>   
 <asp:AsyncFileUpload  ID="AsyncFileUpload1" OnClientUploadComplete="uploadComplete" OnClientUploadError="uploadError"  runat="server" Width="400px" UploaderStyle="Modern" CompleteBackColor = "White" UploadingBackColor="#CCFFFF"  ThrobberID="Image1"OnUploadedComplete = "FileUploadComplete" BackColor="#54AB82" />    
    <asp:Image ID="Image1" runat="server" ImageUrl="~/images......jpg" />    <br />  
 <asp:Label ID="lblMesg" runat="server" BackColor="#CECACD"></asp:Label> 
  </ContentTemplate>  
</asp:UpdatePanel>  
 </div>
</form>

code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void FileUploadComplete(object sender, EventArgs e)
    {
        string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);
        AsyncFileUpload1.SaveAs(Server.MapPath("raj") + filename);
    }
} 

No comments:

Post a Comment