aspnet-js-aspxclientuploadcontrolvalidationerrortypeconsts.md
Declares client constants containing codes of validation errors that can occur while selecting files for uploading.
declare class ASPxClientUploadControlValidationErrorTypeConsts
The ASPxClientUploadControlValidationErrorTypeConsts is a service client object containing constants whose values can be used when handling the ASPxClientUploadControl.ValidationErrorOccurred client-side event.
The following example illustrates how to use the ASPxClientUploadControl.ValidationErrorOccurred event to customize an error message for files that didn’t pass validation.
function onUploadControlValidationErrorOccured(s, e) {
e.showAlert = false;
var errorHtmlContentTemplate = "<div class=\"error-attention\">Attention!</div>
" +
"{0} files are invalid and will not be uploaded.
{1}" +
"All files listed above have been removed from the selection.";
var preparedErrorHtmlContent = errorHtmlContentTemplate
.replace("{0}", e.invalidFiles.length)
.replace("{1}", getDetailsErrorInfoHtml(e));
popupControl.SetContentHtml(preparedErrorHtmlContent);
popupControl.Show();
}
function getDetailsErrorInfoHtml(e) {
var html = "";
html += getDetailsErrorInfoHtmlByErrorType(e, ASPxClientUploadControlValidationErrorTypeConsts.MaxFileCountExceeded,
"These files exceed the allowed file count (the maximum file count is {0}):
<ul>{1}</ul>
",
e.validationSettings.maxFileCount);
html += getDetailsErrorInfoHtmlByErrorType(e, ASPxClientUploadControlValidationErrorTypeConsts.MaxFileSizeExceeded,
"These files exceed the allowed file size (the maximum file size is {0} bytes):
<ul>{1}</ul>
",
e.validationSettings.maxFileSize, true);
html += getDetailsErrorInfoHtmlByErrorType(e, ASPxClientUploadControlValidationErrorTypeConsts.NotAllowedFileExtension,
"Extensions of these files are not allowed (valid extensions are - {0}):
<ul>{1}</ul>
",
e.validationSettings.allowedFileExtensions.join(', '));
html += getDetailsErrorInfoHtmlByErrorType(e, ASPxClientUploadControlValidationErrorTypeConsts.FileNameContainInvalidCharacter,
"Names of this files contain invalid characters ({0}):
<ul>{1}</ul>
",
e.validationSettings.invalidFileNameCharacters.join(","));
return html;
}
function getDetailsErrorInfoHtmlByErrorType(e, errorType, message, commonInfo, isFileSize) {
var filesInfo = getFilesInfoByErrorType(e.invalidFiles, errorType);
if (filesInfo.length == 0)
return "";
var filesHtml = "";
for (var i = 0, len = filesInfo.length; i < len; i++) {
var f = filesInfo[i];
var fileText = isFileSize ? f.fileName + " - " + f.fileSize + " bytes" : f.fileName;
filesHtml += "<li class=\"error-file\">" + fileText + "</li>";
}
return "<div class=\"error-detail\">" + message.replace("{0}", commonInfo).replace("{1}", filesHtml) + "</div>";
}
function getFilesInfoByErrorType(invalidFiles, errorType) {
var filesInfo = [];
for (var i = 0, len = invalidFiles.length; i < len; i++) {
var fileInfo = invalidFiles[i];
if (fileInfo.errorType == errorType)
filesInfo.push(fileInfo);
}
return filesInfo;
}
<head runat="server">
<style>
.upload-validationInfo
{
font: 8pt Tahoma, Geneva, sans-serif;
}
.popup-okButton
{
margin: 6px 6px 6px 210px;
}
.error-attention
{
text-decoration: underline;
font-weight: bold;
}
.error-detail
{
color: #FF0000;
}
.error-file
{
background: #FFC8C8 none;
font-style: italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxUploadControl ID="ASPxUploadControl2" runat="server" Width="320"
NullText="Select multiple files..." UploadMode="Advanced" ShowUploadButton="True">
<AdvancedModeSettings EnableMultiSelect="True" EnableFileList="True" />
<ValidationSettings MaxFileSize="4194304" AllowedFileExtensions=".jpg,.jpeg" MaxFileCount="2" />
<ClientSideEvents ValidationErrorOccurred="onUploadControlValidationErrorOccured" />
</dx:ASPxUploadControl>
<dx:ASPxPopupControl ID="PopupControl" runat="server" ClientInstanceName="popupControl" Modal="true" HeaderText="Validation error"
PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
ShowCloseButton="true" CloseAction="CloseButton" ShowFooter="true">
<FooterTemplate>
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="OK" AutoPostBack="False"
Width="90" CssClass="popup-okButton" ClientSideEvents-Click="function(s, e) { popupControl.Hide(); }">
</dx:ASPxButton>
</FooterTemplate>
</dx:ASPxPopupControl>
</div>
</form>
</body>
See Also