Shadow Lynx
2006-08-09 05:22:59 UTC
That subject packs a whallop, so let me explain in better detail what's
happening and how it relates to ASPX pages...
In a [large] nutshell, if the first <script /> on a page is of type
"text/vbscript", you cannot use inline JavaScript statements that call
setTimeout with functions that start with a double-underscore. This is
very relavant to ASPX (ASP Dot Net) pages because it means that
AutoPostBacks will fail since they generally call the famous JavaScript
statement "__doPostBack(...)" via a setTimeout call.
If you include a VBScript code block before any other code block on an
ASPX page, the following statement will fail in IE (and the error is
far from obvious since it is untrappable and says only that there is an
Invalid character on line 1, character 2):
"javascript:setTimeout('__doPostBack(\'anyASPXcontrol\',\'\')', 0)"
This is a bug in IE 6 and possibly earlier versions (I only have v6 to
play with.) I do not know if it affects IE 7 as I have not installed
that for testing lately. Note that even though the prefix of
"javascript:" is used, the setTimeout function assumes it's calling a
VBScript function, presumably because the first script block is a
VBScript block.
Here is a very simple page that shows this bug:
http://www.digitolle.net/news/testscriptbug.htm
and here is the source code:
--------
<html>
<head>
<title>Test Script Bug</title>
<!-- script type="text/javascript">
// If JavaScript is the first script, setTimeout works properly
// Unrem this script and both buttons will work.
</script -->
<script type="text/vbscript">
' Just because this VBScript block exists,
' setTimeout uses VBScript naming conventions.
' Therefore, double underscore functions will fail
' Rem this block out, and both buttons will work
' Note that calling the function directly always works.
</script>
</head>
<body>
<script type="text/javascript">
function __x() {
alert("test");
}
</script>
<input type="button" value="This will Work"
onclick="javascript:__x();" />
<br />
<input type="button" value="This will Fail"
onclick="javascript:setTimeout('__x()', 0);" />
</body>
</html>
--------
The obvious workaround is to always include a JavaScript block before
any VBScript blocks, even if it's just an empty block. If anyone else
comes up with the same results on this test, please let me know. Of
course if this is a known issue and I'm beating a dead horse, again,
please let me know because it's an odd issue to look up and it's
definitely a brain stumper if you don't know it exists.
happening and how it relates to ASPX pages...
In a [large] nutshell, if the first <script /> on a page is of type
"text/vbscript", you cannot use inline JavaScript statements that call
setTimeout with functions that start with a double-underscore. This is
very relavant to ASPX (ASP Dot Net) pages because it means that
AutoPostBacks will fail since they generally call the famous JavaScript
statement "__doPostBack(...)" via a setTimeout call.
If you include a VBScript code block before any other code block on an
ASPX page, the following statement will fail in IE (and the error is
far from obvious since it is untrappable and says only that there is an
Invalid character on line 1, character 2):
"javascript:setTimeout('__doPostBack(\'anyASPXcontrol\',\'\')', 0)"
This is a bug in IE 6 and possibly earlier versions (I only have v6 to
play with.) I do not know if it affects IE 7 as I have not installed
that for testing lately. Note that even though the prefix of
"javascript:" is used, the setTimeout function assumes it's calling a
VBScript function, presumably because the first script block is a
VBScript block.
Here is a very simple page that shows this bug:
http://www.digitolle.net/news/testscriptbug.htm
and here is the source code:
--------
<html>
<head>
<title>Test Script Bug</title>
<!-- script type="text/javascript">
// If JavaScript is the first script, setTimeout works properly
// Unrem this script and both buttons will work.
</script -->
<script type="text/vbscript">
' Just because this VBScript block exists,
' setTimeout uses VBScript naming conventions.
' Therefore, double underscore functions will fail
' Rem this block out, and both buttons will work
' Note that calling the function directly always works.
</script>
</head>
<body>
<script type="text/javascript">
function __x() {
alert("test");
}
</script>
<input type="button" value="This will Work"
onclick="javascript:__x();" />
<br />
<input type="button" value="This will Fail"
onclick="javascript:setTimeout('__x()', 0);" />
</body>
</html>
--------
The obvious workaround is to always include a JavaScript block before
any VBScript blocks, even if it's just an empty block. If anyone else
comes up with the same results on this test, please let me know. Of
course if this is a known issue and I'm beating a dead horse, again,
please let me know because it's an odd issue to look up and it's
definitely a brain stumper if you don't know it exists.