ASPxUploadControl.FilesUploadComplete Event
Occurs after all the selected files have been uploaded to the server.
Namespace: DevExpress.Web
Assembly:
DevExpress.Web.v24.2.dll
Declaration
public event EventHandler<FilesUploadCompleteEventArgs> FilesUploadComplete
Public Event FilesUploadComplete As EventHandler(Of FilesUploadCompleteEventArgs)
Event Data
The FilesUploadComplete event's data class is FilesUploadCompleteEventArgs.
The following properties provide information specific to this event:
Property |
Description |
CallbackData |
Gets or sets a string that contains specific information (if any) to be passed from the server side to the client.
|
ErrorText |
Gets or sets the error text to be displayed within the control’s error frame if the file upload fails.
|
File uploads can be initiated by clicking the upload button, in code (using the ASPxClientUploadControl.Upload method), or automatically (on the next round trip to the server, e.g., on a button click or page refresh). Handle the FilesUploadComplete event to perform specific server operations after upload of all the selected files has been completed on the server side. The FilesUploadComplete event occurs after the ASPxUploadControl.FileUploadComplete event for each of the selected files has been raised. To access the uploaded files, use the ASPxUploadControl.UploadedFiles property.
Note
When the ASPxUploadControl.FileUploadMode property is set to the default BeforePageLoad value, a file is uploaded and the request execution is aborted before the Page_Init method is called. Thus, controls are not initialized and not available in the FilesUploadComplete event. Set the ASPxUploadControl.FileUploadMode property to OnPageLoad to rebuild the page hierarchy before the ASPxUploadControl requires it. In this case, control properties are available in the FilesUploadComplete event. For more information see the Page Life Cycle During File Upload topic.
Example
This sample demonstrates how files selected within the ASPxUploadControl can be uploaded via either postback or callback, and how the uploaded files can be saved on the server side by using the FilesUploadComplete event.
View Example
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxUploadControl;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e){
}
protected void ASPxUploadControl1_FilesUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FilesUploadCompleteEventArgs e){
// Intentionally pauses server-side processing to demonstrate the Loading Panel or Progress Panel functionality
System.Threading.Thread.Sleep(2000);
ASPxUploadControl uploadControl = sender as ASPxUploadControl;
if (uploadControl.UploadedFiles != null && uploadControl.UploadedFiles.Length > 0){
for (int i = 0; i < uploadControl.UploadedFiles.Length; i++){
UploadedFile file = uploadControl.UploadedFiles[i];
if (file.FileName != ""){
string fileName = string.Format("{0}{1}", MapPath("~/Images/"), file.FileName);
//file.SaveAs(fileName, true);//OnLine Demo Restriction
}
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.2.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxUploadControl" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.2.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.2.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxLoadingPanel" TagPrefix="dx" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript">
function UpdateUploadButton() {
var isAnyFileSelected = false;
for (var i = 0; i < uploadControl.GetFileInputCount(); i++) {
if (uploadControl.GetText(i) != "") { isAnyFileSelected = true; break; }
}
btnUploadViaPostback.SetEnabled(isAnyFileSelected);
btnUploadViaCallback.SetEnabled(isAnyFileSelected);
}
</script>
<dx:ASPxLabel ID="lblAllowebMimeType" runat="server" Text="Allowed image types: jpeg, png">
</dx:ASPxLabel>
<br />
<dx:ASPxUploadControl ID="ASPxUploadControl1" runat="server" Width="400px"
ClientInstanceName="uploadControl" ShowAddRemoveButtons="True"
OnFilesUploadComplete="ASPxUploadControl1_FilesUploadComplete"
ShowProgressPanel="True" > <%-- Progress Panel is in effect in callback mode only. --%>
<ValidationSettings AllowedFileExtensions=".jpg, .png">
</ValidationSettings>
<ClientSideEvents
Init="function(s, e) { UpdateUploadButton(); }"
TextChanged="function(s, e) { UpdateUploadButton(); }"
FilesUploadComplete="function(s, e) { UpdateUploadButton(); }"
FileUploadStart="function(s, e) {
btnUploadViaPostback.SetEnabled(false);
btnUploadViaCallback.SetEnabled(false);
}" />
</dx:ASPxUploadControl>
<br />
<dx:ASPxButton ID="ASPxButton1" runat="server" Width="150px"
AutoPostBack="True" Text="Upload via postback" ClientInstanceName="btnUploadViaPostback">
<ClientSideEvents Click="function(s, e) { loadingPanel.Show(); }" /> <%-- Button click shows a loading panel and generates a postback. --%>
</dx:ASPxButton>
<br />
<dx:ASPxButton ID="ASPxButton2" runat="server" Width="150px"
AutoPostBack="False" Text="Upload via callback" ClientInstanceName="btnUploadViaCallback" >
<ClientSideEvents Click="function(s, e) { uploadControl.Upload(); }" /> <%-- Button click initiates upload via a callback. Progress panel is displayed automatically. --%>
</dx:ASPxButton>
<br />
<%-- Loading Panel is used in this sample to visualize uploads performed via postbacks --%>
<dx:ASPxLoadingPanel ID="ASPxLoadingPanel1" runat="server"
ContainerElementID="ASPxUploadControl1" ClientInstanceName="loadingPanel">
</dx:ASPxLoadingPanel>
</form>
</body>
</html>
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxLoadingPanel" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxUploadControl" tagprefix="dx" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript">
function UpdateUploadButton() {
var isAnyFileSelected = false;
for (var i = 0; i < uploadControl.GetFileInputCount(); i++) {
if (uploadControl.GetText(i) != "") { isAnyFileSelected = true; break; }
}
btnUploadViaPostback.SetEnabled(isAnyFileSelected);
btnUploadViaCallback.SetEnabled(isAnyFileSelected);
}
</script>
<dx:ASPxLabel ID="lblAllowebMimeType" runat="server" Text="Allowed image types: jpeg, png">
</dx:ASPxLabel>
<br />
<dx:ASPxUploadControl ID="ASPxUploadControl1" runat="server" Width="400px"
ClientInstanceName="uploadControl" ShowAddRemoveButtons="True"
OnFilesUploadComplete="ASPxUploadControl1_FilesUploadComplete"
ShowProgressPanel="True" > <%-- Progress Panel is in effect in callback mode only. --%>
<ValidationSettings AllowedFileExtensions=".jpg, .png">
</ValidationSettings>
<ClientSideEvents
Init="function(s, e) { UpdateUploadButton(); }"
TextChanged="function(s, e) { UpdateUploadButton(); }"
FilesUploadComplete="function(s, e) { UpdateUploadButton(); }"
FileUploadStart="function(s, e) {
btnUploadViaPostback.SetEnabled(false);
btnUploadViaCallback.SetEnabled(false);
}" />
</dx:ASPxUploadControl>
<br />
<dx:ASPxButton ID="ASPxButton1" runat="server" Width="150px"
AutoPostBack="True" Text="Upload via postback" ClientInstanceName="btnUploadViaPostback">
<ClientSideEvents Click="function(s, e) { loadingPanel.Show(); }" /> <%-- Button click shows a loading panel and generates a postback. --%>
</dx:ASPxButton>
<br />
<dx:ASPxButton ID="ASPxButton2" runat="server" Width="150px"
AutoPostBack="False" Text="Upload via callback" ClientInstanceName="btnUploadViaCallback" >
<ClientSideEvents Click="function(s, e) { uploadControl.Upload(); }" /> <%-- Button click initiates upload via a callback. Progress panel is displayed automatically. --%>
</dx:ASPxButton>
<br />
<%-- Loading Panel is used in this sample to visualize uploads performed via postbacks --%>
<dx:ASPxLoadingPanel ID="ASPxLoadingPanel1" runat="server"
ContainerElementID="ASPxUploadControl1" ClientInstanceName="loadingPanel">
</dx:ASPxLoadingPanel>
</form>
</body>
</html>
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DevExpress.Web.ASPxUploadControl
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub ASPxUploadControl1_FilesUploadComplete(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxUploadControl.FilesUploadCompleteEventArgs)
' Intentionally pauses server-side processing to demonstrate the Loading Panel or Progress Panel functionality
System.Threading.Thread.Sleep(2000)
Dim uploadControl As ASPxUploadControl = TryCast(sender, ASPxUploadControl)
If uploadControl.UploadedFiles IsNot Nothing AndAlso uploadControl.UploadedFiles.Length > 0 Then
For i As Integer = 0 To uploadControl.UploadedFiles.Length - 1
Dim file As UploadedFile = uploadControl.UploadedFiles(i)
If file.FileName <> "" Then
Dim fileName As String = String.Format("{0}{1}", MapPath("~/Images/"), file.FileName)
'file.SaveAs(fileName, True)'OnLine Demo Restriction
End If
Next i
End If
End Sub
End Class
See Also