First off you need to understand there is a difference in the way server-side script
tags are handled depending on whether the language specified is same as the default language for the page.
The order is this:-
- Run all scripts in
<script runat="server"
tags where the language specified does not match the default language. These are executed in document order. - Run the default script. That means perform the implied writes to the response where there is static content in the page (the stuff not in
runat="server"
tags or inside<% %>
) and any intervening code in<% %>
again in document order obviously. - Run any code at the global level found in
<script runat="server"
tags where the language matches the default script language.
Note that all script has an initial parse before executing phase 1, hence any functions that may be defined by scripts run in phase 3 will be available for caliing from phase 1.