The most accepted way to do this is as follows:-

if <your data code> then
dim sb as new system.text.stringbuilder
sb.append("<script language=""javascript"">" & vbcrlf)
sb.append("Function (TermID)" & vbcrlf)
sb.append("var TermID = prompt(""Enter Terminal ID for " & Session("st") & """);" & vbcrlf)
sb.append("</script>")
page.registerstartupscript("myscript", sb.tostring)
sb = nothing
end if

What this does is correctly places the javascript where it is sure to run once the page has loaded (and all objects are loaded and rendered on the page). It also allows you to access the code and remove it by using the name you give it, myscript, in the case above. The vbcrlf is just to make the code readable in the pages source.