Hello all
I need to use an async file upload control and place it in an ascx file which will be referenced in several pages.
This is the sample code i am working on:
ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucFileUpload.ascx.cs" Inherits="Test.UserControls.ucFileUpload" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><script type="text/javascript" language="javascript">
function uploadError(sender,args)
{
document.getElementById('lblStatus').innerText = args.get_fileName(),
"<span style='color:red;'>" + args.get_errorMessage() + "</span>";
}
function StartUpload(sender,args)
{
document.getElementById('lblStatus').innerText = 'Uploading Started.';
}
function UploadComplete(sender,args)
{
var filename = args.get_fileName();
var contentType = args.get_contentType();
var text = "Size of " + filename + " is " + args.get_length() + " bytes";
if (contentType.length > 0)
{
text += " and content type is '" + contentType + "'.";
}
document.getElementById('lblStatus').innerText = text;
} </script><div><cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnClientUploadError="uploadError"
OnClientUploadStarted="StartUpload" OnClientUploadComplete="UploadComplete" CompleteBackColor="Lime"
UploaderStyle="Modern" ErrorBackColor="Red" ThrobberID="Throbber" OnUploadedComplete="AsyncFileUpload1_UploadedComplete"
UploadingBackColor="#66CCFF" Width="150px" /></div><div><asp:Label ID="Throbber" runat="server" Style="display: none"><img src="../Images/indicator.gif" align="middle" alt="loading" /></asp:Label></div><div><asp:Label ID="lblStatus" runat="server" Style="font-family: Arial; font-size: small;"></asp:Label></div>
cs:
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if (AsyncFileUpload1.HasFile)
{
string strPath = MapPath("~/Images/Dynamic/") + Path.GetFileName(e.FileName);
AsyncFileUpload1.SaveAs(strPath);
}
AsyncFileUpload1.ClearAllFilesFromPersistedStore();
}If in the user control the file upload does not work.
I also need to clear the data of the file upload in order to allow users to upload more files without havind to restart the page.
Any suggestions?