Discussion:
ASPX, VBScript, JavaScript, Double-Underscored Variables and setTimeOut
(too old to reply)
Shadow Lynx
2006-08-09 05:22:59 UTC
Permalink
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.
Peter Bromberg [C# MVP]
2006-08-09 12:00:40 UTC
Permalink
Have you tried setting an emtpy javascript <script... tagset at the beginning?
I seem to recall this as a fix.
peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
Post by Shadow Lynx
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
"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.
http://www.digitolle.net/news/testscriptbug.htm
--------
<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.
Peter Bromberg [C# MVP]
2006-08-09 12:15:01 UTC
Permalink
Sorry, I see you've done that. The piece I remember reading said that the
script engine is initialized by the empty script set. No workaround was
provided, that "is" the workaround.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
Post by Shadow Lynx
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
"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.
http://www.digitolle.net/news/testscriptbug.htm
--------
<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.
Shadow Lynx
2006-08-09 15:35:36 UTC
Permalink
Post by Peter Bromberg [C# MVP]
Sorry, I see you've done that. The piece I remember reading said that the
script engine is initialized by the empty script set. No workaround was
provided, that "is" the workaround.
Now my question is, how long has this bug been around and did they fix
it in IE 7 (which would make me assume that it's not ever going to be
fixed in IE 6). You'd think that with the whole ASPX push, it'd be a
more serious bug to get squashed.
Randy Webb
2006-08-09 16:07:51 UTC
Permalink
Post by Shadow Lynx
Post by Peter Bromberg [C# MVP]
Sorry, I see you've done that. The piece I remember reading said that the
script engine is initialized by the empty script set. No workaround was
provided, that "is" the workaround.
Now my question is, how long has this bug been around and did they fix
it in IE 7
No, it didn't get "fixed".
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dave Massy [MSFT]
2006-08-09 16:02:52 UTC
Permalink
Hi Shadow,
This is not a bug but is by design. Once a particular script language is
declared it is used for the rest of the document.
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/script.asp?frame=true
If you wish to use JScript statements in the same document then you need to
be specific about the language after the VBScript declaration. You can do
this by setting the language on the element with teh event handler
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/language.asp

Thanks
-Dave
Post by Shadow Lynx
Post by Peter Bromberg [C# MVP]
Sorry, I see you've done that. The piece I remember reading said that the
script engine is initialized by the empty script set. No workaround was
provided, that "is" the workaround.
Now my question is, how long has this bug been around and did they fix
it in IE 7 (which would make me assume that it's not ever going to be
fixed in IE 6). You'd think that with the whole ASPX push, it'd be a
more serious bug to get squashed.
Dave Anderson
2006-08-09 16:27:45 UTC
Permalink
Post by Shadow Lynx
Now my question is, how long has this bug been around and did
they fix it in IE 7 (which would make me assume that it's not
ever going to be fixed in IE 6). You'd think that with the whole
ASPX push, it'd be a more serious bug to get squashed.
I'd hardly call it serious -- much less a bug. Pick a language and stick to
it. You don't demand that IE follow the strict box model for some elements
in a document and quirks mode for others, do you?

If there's any *bug* in the system you describe, it's the introduction of
VBScript to the client-side. If I were MS, I would be in no hurry to make my
aspx pages broken in a significant number of browsers.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Shadow Lynx
2006-08-09 18:30:53 UTC
Permalink
Post by Dave Anderson
I'd hardly call it serious -- much less a bug. Pick a language and stick to
it. You don't demand that IE follow the strict box model for some elements
in a document and quirks mode for others, do you?
If there's any *bug* in the system you describe, it's the introduction of
VBScript to the client-side. If I were MS, I would be in no hurry to make my
aspx pages broken in a significant number of browsers.
I actually assumed that it was by design as far as IE was concerned.
The actual "bug" I am referring to is in reference to ASPX.
Specifically, auto-generated client-side code such as
"javascript:setTimeout('__doPostBack(\'anyASPXcontrol\',\'\')', 0)"
will break if a VBScript block is the first script block on the page.
This is, of course, out of my hands as it's an ASPX issue. Microsoft
would need to fix their statement so that the setTimeout function
specifies the JavaScript language.

Please note that Microsoft is not using VBScript for ASPX pages, but I
and others may choose to use VBScript code for various reasons, and if
we do, we can potentially "break" the vast majority of client-side code
generated by ASP.NET and the reason the code stops working isn't all
that obvious.
Dave Anderson
2006-08-09 19:40:32 UTC
Permalink
...but I and others may choose to use VBScript code for
various reasons, and if we do, we can potentially "break"
the vast majority of client-side code generated by ASP.NET
and the reason the code stops working isn't all that
obvious.
In my opinion, [not using VBScript on the client] should have been an
obvious choice from the beginning. ASP.NET would have been a business
failure if it did not generate widely-compatible code, so Microsoft wisely
deferred to JScript.

You should thank them. They trumped your "various reasons" before you wrote
yourself deeper into a corner by writing for an ever-shrinking market share:
http://www.w3schools.com/browsers/browsers_stats.asp

For what it's worth, I have absolutely nothing against IE other than its
failure to correct implementation errors in areas it purports to have
conformance (document.getElementById() and Number.toFixed() come to mind). I
don't even CARE that it supports VBScript. I only care that nobody else
does, so I do not send VBScript to the client.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Martin Honnen
2006-08-09 16:10:14 UTC
Permalink
Followup-to set to microsoft.public.scripting.jscript
Post by Shadow Lynx
This is a bug in IE 6 and possibly earlier versions (I only have v6 to
play with.)
In IE setTimeout takes a third parameter to indicate the script
language, see
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/settimeout.asp>
So I am not sure the IE developers regard the behavior you see as a bug.
There is a way with setTimeout to indicate a language other than the
default script language (which is decided by the first script element).

And another workaround in JavaScript is to simply pass in a function and
not a string see
<http://home.arcor.de/martin.honnen/javascript/2006/08/test2006080901.html>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Walter Zackery
2006-08-09 16:37:03 UTC
Permalink
"Shadow Lynx" <***@yahoo.com> wrote in message news:***@m73g2000cwd.googlegroups.com...
: 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.
:

Another workaround is to leave the vbscript block in place (that may be a
neccessity for other reasons) but to wrap the setTimeout function call.

<input type="button" value="This will Fail"
onclick="javascript:setTimeout(function(){__x()}, 0);" />

You can also wrap the function name in brackets to make it acceptable to
VBScript.

<input type="button" value="This will Fail"
onclick="javascript:setTimeout('[__x]()', 0);" />

Or you can you call an external function that in turn calls the problem
function.

function x(){__x();}
<input type="button" value="This will Fail"
onclick="javascript:setTimeout('x()', 0);" />
f***@gmail.com
2017-04-02 12:06:27 UTC
Permalink
Post by Shadow Lynx
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
"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.
http://www.digitolle.net/news/testscriptbug.htm
--------
<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.
WOW! Awesome. I spent a hours to solve this!!!!!

Loading...