Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a html5 image viewer in asp.net.am testing the script with .html page it was working fine.when using the script in .aspx page it throws me the following error


error:0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'getContext'

the bold line throws the above error


JavaScript
<script>
        function loadImages(sources, callback) {
            var images = {};
            var loadedImages = 0;
            var numImages = 0;
            // get num of sources
            for (var src in sources) {
                numImages++;
            }
            for (var src in sources) {
                images[src] = new Image();
                images[src].onload = function () {
                    if (++loadedImages >= numImages) {
                        callback(images);
                    }
                };
                images[src].src = sources[src];
            }
        }
        var canvas = document.getElementById('myCanvas');
        var context = canvas.getContext('2d');

        var sources = {
            web1: 'http://localhost:2861/images/1.jpg',
            web2: 'http://localhost:2861/images/2.jpg'
        };

        loadImages(sources, function (images) {
            context.drawImage(images.web1, 100, 35, 256, 256);
            context.drawImage(images.web2, 350, 55, 93, 104);
        });

   </script>
Posted
Updated 2-Jan-13 2:46am
v2
Comments
Adam R Harris 2-Jan-13 10:18am    
Sounds like your script is running on the sever side of things. Where is this script located?
Sergey Alexandrovich Kryukov 2-Jan-13 17:42pm    
What do you mean? Server-side JavaScript? Why would you think so? I think this thing is quite rare...
—SA
Adam R Harris 2-Jan-13 17:57pm    
Like if he set the runat of his script to be server it would run the JS on the server.
I was doing some classic ASP/HTML5 stuff a little while ago and a fellow dev who wasn't to familiar with server script vs client script got pretty much the same error when his JS was running on the server.

However 2 cups of coffee and a few hours later it sounds like this isnt his issue and that his issue has something to do with his canvas not being on the page or rendered by the time this script runs.
Sergey Alexandrovich Kryukov 2-Jan-13 18:15pm    
Are you going to provide OP some help?
—SA
Adam R Harris 2-Jan-13 20:14pm    
Christian is on the job, if need be ill jump in there.

1 solution

Have you looked at the object in Chrome to see what it IS and what methods it has ? If you do that for both pages, and the object types are the same, then the only other thing I can think of is if the DTD is somehow changing the nature of your page and the objects on it.

If you paste your HTML verbatim in to an ASPX, does it still give the error ?
 
Share this answer
 
Comments
RAGUNATH V 3-Jan-13 0:20am    
i've already tried using the html code in aspx page.the same error is thrown by visual studio.
Christian Graus 3-Jan-13 0:42am    
Turn off script debugging then, perhaps that's the issue
RAGUNATH V 3-Jan-13 1:05am    
Script debugging is disabled by default and also checked it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900