I read at Does order matter when using different languages in ASP? that the answer is, indeed, yes.
Their recommendation is "don't mix <%%> and <script runat=server>. Use one or the other."
Running through their examples, here's what I extracted.
There are four types of text that you write in an ASP. Three can be executed and one cannot:
[ul][li]<script language="VBScript" runat=server>[/li]
[li]<script language="Javascript" runat=server>[/li]
[li]<% script enclosed in these tags%>[/li]
[li]<HTML>[/li][/ul]
They execute/display in this order, no matter where they are in the source:
[ol][li]The runat=server code that is NOT in the language specified at the top of the sourcesuch as <%@language="vbscript"%> no matter where it is in the source.[/li]
[li]All the HTML and <% %> enclosed script, interleaved together.[/li]
[li]Finally, the runat=server code that IS in the language specified at the top of the page no matter where it is in the source.[/li][/ol]
So the following ASP source
renders as the following page:
The easiest way to remember all this is simple:
[ol][li]Don't use runat=server for the language you specify at the top of the source. In that case, just use script inside <% %> tags. Put another way, only use runat=server when you need the alternate language than that specified at the top. VBScript is the default, so you don't have to specify that.[/li]
[li]runat=server code in the alternate language will run first. Just put it at the top of the source and there will never be any confusion.[/li][/ol]
Their recommendation is "don't mix <%%> and <script runat=server>. Use one or the other."
Running through their examples, here's what I extracted.
There are four types of text that you write in an ASP. Three can be executed and one cannot:
[ul][li]<script language="VBScript" runat=server>[/li]
[li]<script language="Javascript" runat=server>[/li]
[li]<% script enclosed in these tags%>[/li]
[li]<HTML>[/li][/ul]
They execute/display in this order, no matter where they are in the source:
[ol][li]The runat=server code that is NOT in the language specified at the top of the sourcesuch as <%@language="vbscript"%> no matter where it is in the source.[/li]
[li]All the HTML and <% %> enclosed script, interleaved together.[/li]
[li]Finally, the runat=server code that IS in the language specified at the top of the page no matter where it is in the source.[/li][/ol]
So the following ASP source
Code:
<%@language="vbscript"%>
<HTML><BODY>
1 HTML<p>
<script language="VBscript" runat=server>
response.write("2 vbscript runat=server<p>")
</script>
3 HTML<p>
<script language="javascript" runat=server>
Response.Write("4 javascript runat=server<p>");
</script>
5 HTML<p>
<%
Response.write("6 inline script<p>")
%>
7 HTML<p>
<script language="javascript" runat=server>
Response.Write("8 javascript runat=server<p>");
</script>
9 HTML<p>
<script language="VBscript" runat=server>
response.write("10 vbscript runat=server<p>")
</script>
11 HTML<p></BODY></HTML>
Code:
4 javascript runat=server
8 javascript runat=server
1 HTML
3 HTML
5 HTML
6 inline script
7 HTML
9 HTML
11 HTML
2 vbscript runat=server
10 vbscript runat=server
[ol][li]Don't use runat=server for the language you specify at the top of the source. In that case, just use script inside <% %> tags. Put another way, only use runat=server when you need the alternate language than that specified at the top. VBScript is the default, so you don't have to specify that.[/li]
[li]runat=server code in the alternate language will run first. Just put it at the top of the source and there will never be any confusion.[/li][/ol]