|
Home > Archive > IIS ASP > March 2006 > ASP, Javascript and parsing
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
ASP, Javascript and parsing
|
|
| Martin Walke 2006-03-25, 11:59 am |
| Hi all,
Can someone help me out here? I'm been using ASP and VBScript for some years
but have just ventured into the realms of using server side Javascript and
apart from hitting various niggerly problems, this one baffles me.
This is a very simplistic example of the problem.
<%@ Language="JavaScript"%>
<html>
<body>
Here it is
<script language="javascript" runat="server">
Response.Write("in the")
</script>
middle
</body>
</html>
When I run this I get
"Here it is middle in the" rather than "Here it is in the middle".
Can someone tell me why? If I use <%= then it's fine but my main program is
using a javascript server side include which I'm including by using the
<script src ....> as I can't get the <!--#include method to work.
Am I confusing myself totally by messing up what I thought to be VBScript
and Javascript commands? Or is it something to do with the way in which the
page in parsed for server side commands?
TIA
Confused Martin
| |
| Anthony Jones 2006-03-25, 11:59 am |
|
"Martin Walke" <martin.walke_no_spam@vega_dot_co_dot_uk> wrote in message
news:OrQy5I1TGHA.1576@tk2msftngp13.phx.gbl...
> Hi all,
>
> Can someone help me out here? I'm been using ASP and VBScript for some
years
> but have just ventured into the realms of using server side Javascript and
> apart from hitting various niggerly problems, this one baffles me.
>
> This is a very simplistic example of the problem.
>
> <%@ Language="JavaScript"%>
>
> <html>
> <body>
>
> Here it is
> <script language="javascript" runat="server">
> Response.Write("in the")
> </script>
> middle
>
> </body>
> </html>
>
> When I run this I get
>
> "Here it is middle in the" rather than "Here it is in the middle".
>
> Can someone tell me why? If I use <%= then it's fine but my main program
is
> using a javascript server side include which I'm including by using the
> <script src ....> as I can't get the <!--#include method to work.
>
> Am I confusing myself totally by messing up what I thought to be VBScript
> and Javascript commands? Or is it something to do with the way in which
the
> page in parsed for server side commands?
>
> TIA
> Confused Martin
>
First off you can't preform inline response.writes in a <script
runat="server"> tag. It needs to be <% %>
Secondly isn't the real issue here that <!-- #includes aren't working. Why
not?
Thirdly if you change the script tag language to VBScript it appears to run
first before the rest of the document. Then if you change <% language to
VBScript it runs after the rest of the document. If you then change the
script language back to Javascript it runs before the rest of the document.
I won't try to describe here why that so but it does actually make sense.
Anthony.
| |
| Dave Anderson 2006-03-25, 11:59 am |
| Martin Walke wrote:
> [ <script runat=server> -vs- <%%> ]
> Can someone tell me why? If I use <%= then it's fine but my main
> program is using a javascript server side include which I'm including
> by using the <script src ....> as I can't get the <!--#include method
> to work.
http://aspfaq.com/show.asp?id=2045
--
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. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
| |
| Martin Walke 2006-03-27, 9:04 am |
| Thanks Anthony and Dave,
Your link, Dave, gives the detail behind what Anthony is hinting at. I'd
seen this info before but couldn't nail it down.
Seeing this info gives the inherent reason why the #include was not working.
I have a large number of objects defined in the include file that weren't
being recognised by the rest of the code due to the reasons mentioned in
Dave's link.
You *could* almost use this order parsing to your advantage but could be
messy from a maintenance point of view. Anyway......
Thanks again guys. I'll just need to re-structure my code.
Martin
"Anthony Jones" <Ant@yadayadayada.com> wrote in message
news:%23i242p3TGHA.5972@TK2MSFTNGP10.phx.gbl...
>
> "Martin Walke" <martin.walke_no_spam@vega_dot_co_dot_uk> wrote in message
> news:OrQy5I1TGHA.1576@tk2msftngp13.phx.gbl...
> years
> is
> the
>
>
> First off you can't preform inline response.writes in a <script
> runat="server"> tag. It needs to be <% %>
>
> Secondly isn't the real issue here that <!-- #includes aren't working.
> Why
> not?
>
> Thirdly if you change the script tag language to VBScript it appears to
> run
> first before the rest of the document. Then if you change <% language to
> VBScript it runs after the rest of the document. If you then change the
> script language back to Javascript it runs before the rest of the
> document.
>
> I won't try to describe here why that so but it does actually make sense.
>
> Anthony.
>
>
| |
| Dave Anderson 2006-03-27, 9:04 am |
| Martin Walke wrote:
> Thanks Anthony and Dave,
>
> Your link, Dave, gives the detail behind what Anthony is hinting at.
> I'd seen this info before but couldn't nail it down.
>
> Seeing this info gives the inherent reason why the #include was not
> working. I have a large number of objects defined in the include file
> that weren't being recognised by the rest of the code due to the
> reasons mentioned in Dave's link.
>
> You *could* almost use this order parsing to your advantage but could
> be messy from a maintenance point of view. Anyway......
>
> Thanks again guys. I'll just need to re-structure my code.
The situation may not be as dire as you think. My strong recommendation for
using <script runat=server> is to encapsulate everything in functions. If
you do so, you can call those functions from anywhere in the execution order
(even if the called function is in the last order group). I have no idea how
that plays with #include directives, but you could always try it and let us
know.
--
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. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
|
|
|
|
|