This is a migrated thread and some comments may be shown as answers.

javascript error on Upload control

4 Answers 78 Views
Upload
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Neil
Top achievements
Rank 1
Neil asked on 20 Dec 2011, 07:38 PM
For some reason the code below seems to have stopped working for me and when the page loads I get
an error as follows:

"Microsoft JScript runtime error: 'onUpload' is undefined"

as you can see the functions do exist and if I View Source on the page, the scripts are available?

Any help would be greatly appreciated :)

Neil



@{
    ViewBag.Title = "ImageUploader";
    Layout = "~/Views/Shared/LetsPoseLayout.cshtml";
}
 
<div id="response">
</div>
<p>
    Add images from your computer using the <b>Select</b> button below.<br />
    <span class="footnote">(You can browse for more than 1 image before uploading the files)</span></p>
@(Html.Telerik().Upload()
    .Name("attachments")
    .Multiple(true)
    .Async(async => async
        .Save("Save", "Image")
        .Remove("Remove", "Image")
        .AutoUpload(false))
        .ClientEvents(events => events
                .OnSuccess("onSuccess")
                .OnError("onError")
                .OnUpload("onUpload")
            )
    )
<script type="text/javascript">
    $(document).ready(function () {
        $('#response').hide();
    });
 
    function onSuccess(e) {
        $('#response').attr({
            class: 'success'
        })
        .html('You have successfully upload new images to your account')
        .show();
    }
 
    function onError(e) {
        $('#response').attr({
            class: 'error'
        })
        .html(e.XMLHttpRequest.responseText)
        .show();
 
        e.preventDefault();
    }
 
    function onUpload(e) {
        // Array with information about the uploaded files
        var files = e.files;
 
        // Check the extension of each file and abort the upload if it is not .jpg
        $.each(files, function () {
            if (this.extension != ".jpg") {
//                $('#response').attr({
//                    class: 'error'
//                })
//                .html("Error - Only files of type .jpg can be uploaded")
//                .show();
 
                e.preventDefault();
                return false;
            }
        });
    }
</script>

4 Answers, 1 is accepted

Sort by
0
Neil
Top achievements
Rank 1
answered on 22 Dec 2011, 12:11 AM
The problem seems to be related to the compatibility view in IE9. When this is on, I get the error and when I turn it off the error goes away... does anyone know what compatibility mode does to casue a problem like this?
0
Sebastian S
Top achievements
Rank 1
answered on 22 Dec 2011, 04:13 AM
Naw - works fine for me under IE9 with the compatibility stuff.

--Sebastian
0
Jay
Top achievements
Rank 1
answered on 24 Jan 2012, 09:55 PM
I am having the same issue in IE 8.0...anyone have any more information on this?  My code is nearly identical to the OP, and everything works dandy in Firefox.
0
JR
Top achievements
Rank 1
answered on 09 Feb 2012, 09:04 AM
try setting the script on top of the page, before declaring the upload control.
Tags
Upload
Asked by
Neil
Top achievements
Rank 1
Answers by
Neil
Top achievements
Rank 1
Sebastian S
Top achievements
Rank 1
Jay
Top achievements
Rank 1
JR
Top achievements
Rank 1
Share this question
or