Upload file using Ajax AsyncFileUpload in Asp.Net

img
May
21
Spread the love

In this tutorial I’ll Explain I’ll show you ,

How to Upload file using Ajax AsyncFileupload Control in Asp.Net

  • Step 1- Create a new Empty WebSite.
  • Step 2- Install Ajax Control Toolkit in Visual Studio.
  • Step 3- Register Toolkit Script Manager At the Top of your Page.
<%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%>
  • Step 4- Drag

AsyncFileUpload

Control on your page.

Edit AsyncFileUpload Control as follow.

<asp:AsyncFileUpload ID="asynFileupload" runat="server" CompleteBackColor="White"
OnClientUploadComplete="uploadSuccess" OnClientUploadError="uploadFailed"
                ThrobberID="imageUpload" UploaderStyle="Modern"
                OnUploadedComplete="UploadComplete" Height="50px" Width="290px" />

Here you can see I have added some properties to This control.

OnClientUploadComplete : This Property is used to call the Javascript function written in Client Side when file is Uploaded successfully.

OnClientUploadError: This Property is used to call the Javascript function written in Client Side when file is not Uploaded successfully.

ThrobberID: This Property indicate the Id of ProgressBar Images Control.

OnUploadedComplete: This Property is used to Execute the Server side Method after file Upload.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
 
 
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery-2.1.1.min.js"></script>
    <script type="text/javascript">
 
        function uploadSuccess() {
            $('#spanMsg').text('File Uploaded')
 
        }
      
        function uploadFailed() {
            $('#spanMsg').text('File upload Failed');
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
 
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <br />
            <asp:AsyncFileUpload ID="asynFileupload" runat="server" CompleteBackColor="White"
                OnClientUploadComplete="uploadSuccess" OnClientUploadError="uploadFailed"
                ThrobberID="imageUpload" UploaderStyle="Modern"
                OnUploadedComplete="UploadComplete" Height="50px" Width="290px" />
            <asp:Image ID="imageUpload" runat="server" ImageUrl="~/ajax-loader.gif" />
 
            <span id="spanMsg"></span>
        </div>
    </form>
</body>
</html>

I have used an Image Control which will show progess bar while AsyncFileUpload Control will Upload the file.

I have used another control span which will be used to show Success or Error message of AsyncFileUpload Control

Code Behind code

using System;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void UploadComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        string filename = System.IO.Path.GetFileName(asynFileupload.FileName);
        asynFileupload.SaveAs(Server.MapPath("Images/") + filename);
    }
}
 

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Broadband Speed Check
    Spread the love Broadband speed refers to the data transfer rate from the internet to your computer.  Broadband speed tests measure […]
  • Compare Internet Service Providers (DSL)
    Spread the love   Verizon DSL Qwest DSL Deluxe AT&T U-Verse High Speed Internet. Maximum connection speed (Download / Upload)* 0.5 -1 […]
  • Compare High Speed 56K Dialup ISP
    Spread the love   PeoplePC AT&T Copper.net EarthLink ISP.com AOL Time usage/m Unlimited Unlimited 200 hr Unlimited Unlimited Unlimited […]
  • DSL vs Cable Internet – Differences between DSL and Cable Internet
    Spread the love DSL internet Cable internet Data transmission via phone line Data transmission via coaxial cable line Connected through DSL modem […]
  • VoIP – Bonus Features
    Spread the love Unlike landline phone service, VoIP providers often provide many bonus features for free.  Some of them are very useful to […]
  • Virtual Telephone Number – What is a virtual telephone number?
    Spread the love A virtual telephone number is simply a phone number that doesn’t have a directly-associated phone line.  It is a vanity number […]
  • Satellite VoIP
    Spread the love The market of VoIP has been expanding rapidly over the past few years.  VoIP allows the transmission of voice signals over the […]
  • VoIP – FAQ
    Spread the love VoIP is a relatively new phone service to many consumers.  Some of you may have hesitations when transferring your phone service from […]
  • Cable Internet Service Providers
    Spread the love Comcast Cable Internet Maximum connection speed: 8 Mbps / 384 kbps (download speed up to 100 times faster than 56K dialup) $75 Cash […]
  • Broadband DSL. What does DSL stand for?
    Spread the love DSL stands for “Digital Subscriber Line”. It is a family of technologies that provides digital data transmission over the wires of […]
  • Broadband Internet
    Spread the love Broadband Internet, also called High Speed Internet, is an internet connection offering high data transmission rate of 256 Kbps […]
  • Wireless Internet Service Providers
    Spread the love AT&T Wi-Fi service can connect you with public wireless high speed internet access at speeds much faster than dialup when you are […]
  • Satellite Internet Providers
    Spread the love HughesNetTM offers affordable, super-fast, always-on, satellite Internet access and is available anywhere in the contiguous […]
  • VoIP for Small Business
    Spread the love VoIP, or voice over internet protocol, is a technology that has revolutionized the way businesses communicate today. This technology […]
  • Wireless Internet / Wi-Fi
    Spread the love How does wireless internet work?  Wireless internet transfers digital data using radio frequency. Wi-Fi is the leading wireless […]
  • Ten Tips for Choosing a VoIP Provider
    Spread the love What should you consider when choosing a VoIP provider? Read our simple tips and do your own VoIP comparisons before making your […]
  • Satellite Internet
    Spread the love Satellite Internet Access is probably the most expensive high speed internet service for home users. However, in rural or remote […]
  • Best VoIP Providers
    Spread the love VoIPo Residential VoIP Key Features: Unlimited Calls to US/Canada Over 38 Calling Features 2nd Line (Cloned) Free Equipment Free […]
  • ISP: Tips for Choosing a Good Broadband ISP
    Spread the love For those who are relocating or moving from dialup to broadband internet access, choosing a broadband ISP can cause some headaches. […]
  • 56K Dialup ISP / High Speed Dialup ISP
    Spread the love PeoplePC Accelerated Unlimited internet access Accelerated technology increases speed by up to 5X Smart dialer technology (dial the […]