AjaxFileUpload Control (demo)

AjaxFileUpload is an ASP.NET AJAX Control that allows you to asynchronously upload files to the server.

Properties

Name Description
AllowedFileTypes A comma-separated list of allowed file extensions. The default is an empty string.
ChunkSize The size of a chunk used by HTML5 to upload large files in bytes. The default is 4096.
IsInFileUploadPostBack This will be true when a postback will be performed from the control. This can be used to avoid execution of unnecessary code during a partial postback. The default is false.
MaximumNumberOfFiles A maximum number of files in an upload queue. The default is 10.
Mode How AjaxFileUpload displays a progress bar. The default is Auto.
OnClientUploadComplete The name of a JavaScript function executed on the client side after a file is uploaded successfully.
OnClientUploadCompleteAll The client script that executes when all of files in queue uploaded, or when user hits Cancel button to stop uploading
OnClientUploadError The name of a JavaScript function executed on the client side if the file upload failed.
OnClientUploadStart The name of a JavaScript function executed on the client side before any files are uploaded.
ServerPollingSupport Whether or not AjaxFileUpload supports server polling.
ThrobberID The ID of a control that is shown on the file upload. The throbber image is displayed for browsers that do not support the HTML5 File API or server-side polling.

Methods

SaveAs(fileName)
Saves the uploaded file with the specified file name
Params:
  • fileName
    • Type: String
    • Description: Name of the file to save

Events

UploadComplete
An event raised when the file upload is complete.

UploadCompleteAll
An event handler that will be raised when the UploadComplete event is raised in all files in an upload queue, or when a user presses the Cancel button to stop uploading.

UploadStart
An event raised when the file upload starts.

Client properties

allowedFileTypes
A comma-separated list of allowed file extensions.
Getter name: get_allowedFileTypes()
Setter name: set_allowedFileTypes(value)

chunkSize
The size of a chunk used by HTML5 to upload a large file in bytes.
Getter name: get_chunkSize()
Setter name: set_chunkSize(value)

maximumNumberOfFiles
A maximum number of files in an upload queue. Default value is 10.
Getter name: get_maximumNumberOfFiles()
Setter name: set_maximumNumberOfFiles(value)

mode
How AjaxFileUpload displays a progress bar.
Getter name: get_mode()
Setter name: set_mode(value)

postBackUrl
A url of the page where the control is located.
Getter name: get_postBackUrl()
Setter name: set_postBackUrl(value)

serverPollingSupport
Whether or not AjaxFileUpload supports server polling.
Getter name: get_serverPollingSupport()
Setter name: set_serverPollingSupport(value)

throbber
A control that is shown while a file is uploading. The throbber image is displayed for browsers that do not support the HTML5 File API or server-side polling.
Getter name: get_throbber()
Setter name: set_throbber(value)

Client methods

addFileToQueue(item)
The processor will call this method to add a selected file to the queue. It will return true if a file item is successfully added, otherwise, it returnes false.
Params:
  • item
    • Type: Object
    • Description: File to add to the queue

attachEvents(elements)
Attaches the click event hanlder to an upload button.
Params:
  • elements
    • Type: Object
    • Description: Collection of AjaxFileUpload visual elements

cancelUpload()
Cancels upload process.

confirmFileIsInvalid(fileItem)
Sends alert to a user that the file type is not acceptable. The processor uses this method after validation.
Params:
  • fileItem
    • Type: Object
    • Description: File trying to be added to queue

done()
Call this method when all files has been uploaded. This method will reset states of the control.

doneAndUploadNextFile(fileItem)
Marks fileItem as uploaded, and uploads the next file in a queue.
Params:
  • fileItem
    • Type: Object
    • Description: Uploaded file

enableControls(enable)
If set to true, it will set the control state to enabled (ready to upload), otherwise the control will be disabled and the button state turns to the Cancel button.
Params:
  • enable
    • Type: Boolean
    • Description: true to enable controls, otherwise false

fileTypeIsValid(fileType)
Checks whether the file type is allowed to be uploaded by checking it against the AlowedFileTypes property.
Params:
  • fileType
    • Type: String
    • Description: File extension

getCurrentFileItem()
Gets a file item based on the current file id.

getFileItem(id)
Get file in upload queue by ID
Params:
  • id
    • Type: Number
    • Description: File ID

getNextFile()
Gets a file in an upload queue by id.

removeFileFromQueueHandler(e)
Removes a file from the queue and updates user interface.
Params:
  • e
    • Type: Sys.Extended.UI.AjaxFileUpload.Item
    • Description: An item to remove

setAsUploading(fileItem)
Sets the file item status to uploading.
Params:
  • fileItem
    • Type: Sys.Extended.UI.AjaxFileUpload.Item
    • Description: Uploading file

setDefaultElementsLayout(elements)
Sets default elements layout during initializing.
Params:
  • elements
    • Type: Object
    • Description: Elements to set up

setFileStatus(fileItem, fileStatusText, text)
Sets file item status text.
Params:
  • fileItem
    • Type: Sys.Extended.UI.AjaxFileUpload.Item
    • Description: Uploading file
  • fileStatusText
    • Type: String
    • Description: Text displayed in file info container
  • text
    • Type: String
    • Description: Text displayed in status bar

setPercent(percent)
Sets upload percentage.
Params:
  • percent
    • Type: Number
    • Description: Upload percent

setStatusMessage(msg)
Sets a message in a status bar.
Params:
  • msg
    • Type: String
    • Description: Text to set

Client events

uploadComplete
Occurs when the file upload completes.
Add event handler method: add_uploadComplete(handler)
Remove event handler method: remove_uploadComplete(handler)
Raise event method: raise_uploadComplete()

uploadCompleteAll
An event handler that will be raised when the UploadComplete event is raised in all files in an upload queue, or when a user presses the Cancel button to stop uploading.
Add event handler method: add_uploadCompleteAll(handler)
Remove event handler method: remove_uploadCompleteAll(handler)
Raise event method: raise_uploadCompleteAll()

uploadError
An event handler raised when an upload error occurs.
Add event handler method: add_uploadError(handler)
Remove event handler method: remove_uploadError(handler)
Raise event method: raise_uploadError()

uploadStart
Occurs when the file upload starts
Add event handler method: add_uploadStart(handler)
Remove event handler method: remove_uploadStart(handler)
Raise event method: raise_uploadStart()

Last edited Sep 14, 2015 at 10:11 AM by fadilmamedov, version 5