%@LANGUAGE=VBScript%>
<%@LANGUAGE=JAVASCRIPT%>
<% %>
to encapsulate their code, and are done with it.
However, ASP pages can actually use a combination of both languages if you so desire (or perhaps I should say, "If you need to") by using server-side script blocks such as:
<script runat=server language=vbscript>
...
</script>
In an attempt to discover how and when you may variables and functions from one block of code in another, this test page was created and the following conclusions drawn. [See the test code and its output below the conclusions.]
Note that after writing this page, I was pointed to a page on MSDN which covers much of this information.
<script runat=server>
blocks is run at a different time from the code in <% %>
.<script runat=server>
code from non-default language.<% %>
code.<script runat=server>
code from default language.As a slight exception to the above, functions written in a <script runat=server>
block in the non-default language may access variables defined in <% %>
, provided the function is called from within <% %>
.
<script runat=server>
block are not accessible outside that block.<script runat=server>
blocks cannot see these variables, nor can <% %>
code blocks.
<script runat=server>
blocks may be called or referenced from inside vbscript <% %>
tags.<% %>
may not be used in <script runat=server>
because of #1 above.)
<script runat=server>
functions and variables accessed from within VBScript <script runat=server>
or <% %>
code blocks are case-insensitive.
function DoTheRightThing(){...}
DOTHERIGHTTHING()
dotherightthing()
dOtHerIGHTthInG()
<script runat=server>
and referred to in another JavaScript <script runat=server>
block are case sensitive.var foo
then you may not refer to it as Foo
or FOO
in another JavaScript block.
<%@LANGUAGE=VBScript%> <% Dim fooVB fooVB = "fooVB" %> <SCRIPT LANGUAGE=VBScript RUNAT=SERVER> Dim fooVB1 fooVB1 = "fooVB1" </SCRIPT> <SCRIPT LANGUAGE=JavaScript RUNAT=SERVER> var fooJS1 = "fooJS1"; //var fooFromVB = fooVB1+" was readable in JS1" //The previous line doesn't work--JS cannot get at the fooVB1 variable. //See #1 above </SCRIPT> <SCRIPT LANGUAGE=VBScript RUNAT=SERVER> Dim fooFromJS fooFromJS = fooJS1+" was readable in VB2" 'The previous line does work, but as per #2 above, 'this variable can never be used by the <% %> code below. fooFromVB = fooVB1+" was readable in VB2" Response.Write(fooFromJS) 'Note that the previous line takes effect at the VERY end of the page, after </html> </SCRIPT> <SCRIPT LANGUAGE=JavaScript RUNAT=SERVER> var fooFromJS2 = fooJS1+" was readable in JS2" </SCRIPT> <SCRIPT LANGUAGE=JavaScript RUNAT=SERVER> function OneThroughTen(){ for (var i=0;i<10;i++) Response.Write(i+"<br>"); } function WriteFoo(){ Response.Write(FOOVB+"<br>\n"); if (Response.Buffer) Response.Flush(); } function WriteFooVB1(){ Response.Write(FOOVB1+"<br>\n"); if (Response.Buffer) Response.Flush(); } function WriteFooJS1(){ //Note that case matters for the following js variable //"FOOJS1" does not work here Response.Write(fooJS1+"<br>\n"); if (Response.Buffer) Response.Flush(); } </SCRIPT> <pre> <%=fooVB%> aka <%=FOOVB%><br> <%=fooVB1%> aka <%=FOOVB1%><br> <%=fooJS1%> aka <%=FOOJS1%><br> <br> fooFromVB : <%=fooFromVB%><br> fooFromJS : <%=fooFromJS%><br> fooFromJS2 : <%=fooFromJS2%><br> </pre> <% ONETHROUGHTEN() WRITEFOO() WRITEFOOVB1() WRITEFOOJS1() %>
No longer available as this server is no longer on IIS