I was working on a project recently working on the master page of a .Net 2.0 Web Application and I encountered the most ambiguous error message. I was removing style sheet controls that were going to be added to a dynamic Page style mechanism when I first ran into the error. I had been going through the tags removing the trailing ASP control tags with the /> tag to end the control markup.
I did this on a JavaScript tag changing from this:
<script type="text/javascript" language="javascript" src="../scripts/vkboards.js”></script>
To this:
<script type="text/javascript" language="javascript" src="../scripts/vkboards.js"/>
Everything compiled fine but when I ran the project I kept getting this error message:
Microsoft JScript runtime error: 'document.body' is null or not an object.
Code Segment:
var _b=document.createElement("div");
var _c=document.createElement("div");
_b.style.visibility="hidden";
_b.style.position="absolute";
_b.style.fontSize="1px";
_c.style.height="0px";
_c.style.overflow="hidden";
document.body.appendChild(_b).appendChild(_c);
It was really strange and i took a look again at my code and the only thing I could think was that all the JavaScript included file gets inserted on the page rendering in-between where the beginning script markup and the end tag markup is located. I didn’t see this happening on the page markup when the exception was thrown, but that’s my best guess for now. If you’ve run into this error it’s easy enough to fix just add an ending tag, </script> in this case, and the exception will be diverted.
ASP.Net, Programming