I'm trying to use the AsyncFileUpload control along with an UpdatePanel and UpdateProgress but can't seem to get it to work correctly.
What I want to do is use the AsyncFileUpload to select a file to process, click a button, have the UpdateProgress control display an animated gif and message "Processing file...", when the processing is complete some text like "Processing complete" is written to a Label.
Right now with my current code, before the page loads I get an unresponsive script warning. I click "Stop script" in the window displaying the script warning to close the window. I can click the AsyncFileUpload button and upload a file for processing, but then when I click the button to process the file, the UpdateProgress does not display. When the file is finished "processing" the message is displayed in the Label correctly.
Below is my code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title></head><body><form id="form1" runat="server"><div><asp:ToolkitScriptManager ID="ScriptManager1" runat="server"></asp:ToolkitScriptManager><asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"><Triggers><asp:PostBackTrigger ControlID="ProcessButton" /></Triggers><ContentTemplate><div><asp:AsyncFileUpload ID="AsyncFileUpload" runat="server" Width="480px" UploaderStyle="Modern" /></div><div><asp:Button ID="ProcessButton" runat="server" TabIndex="2" Text="Process" OnClick="ProcessButton_Click" /></div><div><asp:Label ID="MessageLabel" runat="server" /></div></ContentTemplate></asp:UpdatePanel><asp:UpdateProgress ID="UpdateProgress1" runat="Server" AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="1"><ProgressTemplate><div><img src="loading.gif" /> Please wait ...</div></ProgressTemplate></asp:UpdateProgress></div></form></body></html>
using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication2 { public partial class WebForm2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void ProcessButton_Click(object sender, EventArgs e) { string fileName = this.AsyncFileUpload.FileName; // Simulate processing the file. Thread.Sleep(5000); this.MessageLabel.Text = String.Format("The file '{0}' was processed on {1} at {2}", fileName, DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString()); this.MessageLabel.Visible = true; } } }