New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

RadAsyncUpload Object

The following table lists the important RadAsyncUpload client-side methods:

 

NameParametersReturn TypeDescription
addFileInputnonenoneAdds a new row to the RadAsyncUpload control. See Example 1.
deleteFileInputAtintegernoneDeletes the row at the specified (0-based) index if it exists. See Example 2.
deleteAllFileInputsnonenoneDeletes all rows with the uploaded files.
getUploadedFilesnonearrayReturns an array containing the names of the uploaded files. See Example 3.
getIDstringstringCreates a new ID, based on the RadAsyncUpload ClientID, the supplied parameter, and the zero based index of the current row. See Example 4.
isExtensionValidstringbooleanValidates the extension of the file name that is passed as a parameter. See Example 5.
get_maxFileCountnoneintegerReturns the maximum number of rows in the RadAsyncUpload control.
set_maxFileCountintegernoneSets the maximum number of rows in the RadAsyncUpload control.
get_initialFileInputsCountnoneintegerReturns the initial number of rows when the RadAsyncUpload control is first loaded.
get_allowedFileExtensionsnonearrayReturns an array containing the allowed file extensions.
get_elementnoneHTML elementReturns the DOM element for the RadAsyncUpload control.
get_loadedModuleNamenonestringReturns string representation of the loaded upload module name. It could be one of the following: Silverlight/Flash/IFrame

Example 1: Add a new row to the RadAsyncUpload.

ASPNET
<telerik:RadAsyncUpload RenderMode="Lightweight" runat="server" id="RadAsyncUpload1" />
<input type="button" value="Add" onclick="myAdd()" />
<script type="text/javascript">
    function myAdd() {
        $find("<%= RadAsyncUpload1.ClientID%>").addFileInput();
    }
</script>

Example 2: Delete the file at the specified index.

JavaScript
function DeleteInvalidFiles() {
  var upload = $find("<%= RadAsyncUpload1.ClientID %>");
  var inputs = upload.getUploadedFiles();
  for (i = inputs.length - 1; i >= 0;i--) {
    if(!upload.isExtensionValid(inputs[i].value))
       upload.deleteFileInputAt(i);
  }
}		

Be careful to use the right index because in different scenarios file inputs may be ordered differently in RadAsyncUpload .

Example 3: Get the uploaded files names.

JavaScript
function ClearInvalidInputs() {
  var upload = $find("<%= RadAsyncUpload1.ClientID %>");
  var inputs = upload.getUploadedFiles();
  for (i = inputs.length - 1; i >= 0;i--) {
    alert(inputs[i] + " was  uploaded");    
  }
}			

Example 4: Create a new ID.

ASPNET
<telerik:RadAsyncUpload RenderMode="Lightweight" runat="server" id="RadAsyncUpload1" OnClientAdded="addTitle" />
<script type="text/javascript">
    function addTitle(RadAsyncUpload, args) {
        var row = args.get_row();
        var title = document.createElement("input");
        title.id = title.name = RadAsyncUpload.getID("title");
        row.insertBefore(title, row.firstChild);
    }
</script>

This method must be used when adding custom fields to a RadAsyncUpload instance.

Example 5: Validate the file extension.

JavaScript
function ClearInvalidInputs() {
	var upload = $find("<%= RadAsyncUpload1.ClientID %>");
	var inputs = upload.getUploadedFiles();
	for (i = inputs.length - 1; i >=0; i--) {
	if (!upload.isExtensionValid(inputs[i]))
		alert("extension is invalid!")	  
}		

See Also

Getting Started

Client-Side Basics

Client-Side Events

In this article
See Also
Not finding the help you need?
Contact Support