I have an instance of WebUpload control that I need to configure to fire the Upload events on the server side, but I still want to trap when the user selects files with the wrong extension on the client side.
In my ascx file, I have coded
<igjq:WebUpload ID="igUpload1" runat="server" OnUploadFinishing="igUpload1_OnUploadFinishing" OnUploadFinished="igUpload1_OnUploadFinished" OnUploadStarting="igUpload1_OnUploadStarting"> <ClientEvents OnError="showAlert" /> </igjq:WebUpload>
In the code behind (CS) file, I have
$.ig.loader(function () { $("#igUpload1").igUpload({ mode: 'multiple', multipleFiles: true, maxUploadedFiles: 5, maxSimultaneousFilesUploads: 1, allowedExtensions: ["txt", "doc", "png"], progressUrl: "Services/IGUploadStatusHandler.ashx", controlId: "serverID1", iguploadonerror: function (e, args) { showAlert(e, args); }, onError: function (e, args) { showAlert(e, args); } )};)};
When I code the OnUploadStarting to cancel the event with a server message, the onError event does fire and I can display the message there. This is good.
However, when I test the client side by selecting a file with a bad extension, neither error event fires.
What do I need to change to trap the OnError event on the client?
Hello Gerald,
Thank you for posting in our community!
Have you tested this scenario by using the errorMessageValidatingFileExtension option for the igUpload?
I have added a code snippet for your reference:
$(".selector").igUpload({
errorMessageValidatingFileExtension : "File extension not supported"
});
More information on error message types could be found at the option tab of the following page: http://help.infragistics.com/jQuery/2013.1/ui.igupload
If you have any further question feel free to contact me.
Dimka,
Thanks for your response, but I already have info on that errorMessage option.
My problem is that I have coded to allow three file extensions
allowedExtensions: ["txt", "doc", "png"]
but the upload control still allows me to pick a .html file and it uploads it.
I was expecting or hoping that the control would catch this and fire some error event where I could handle the message.
Gerald
Feel free to contact us again when you have your requirements revised or if any additional questions arise meanwhile.
Thank you for the time that you spent on this question.
My problem seems to be that I am mixing the client and server events. Once I had coded runat="server", the client-side events stopped firing.
I guess this makes sense. I will have to rethink what I want to do when the client uses the control and decide on either client-side or server-side.
The sample in .zip format
I have managed to implement your requirement. The following code is used for the igUpload implementation:
<script>
$(function () {
$('#igUpload1').igUpload(
{
autostartupload: true,
ProgressUrl: "/IGUploadStatusHandler.ashx",
controlId: "igUpload1",
allowedExtensions: ["txt", "doc", "png"],
errorMessageValidatingFileExtension: "File extension not supported",
onError: function (evt, ui) {
alert(ui.errorMessage.toString())
}
</script>
<div id="igUpload1"></div>
I have attached the whole sample in order to represent the desired behavior. Feel free to modify it and use it in your custom projects if needed.
If you need further assistance or if any new questions arise feel free to contact me again.