JScript code for both server side and client side 
Author Message
 JScript code for both server side and client side

I'm trying to have only one file that contains the JScript code that can be
used on both the server side ASP pages and the client side HTML page.  The
file contains functions to do conversion from Metric to Imperial and back.
Sometimes I want to use the function on the server side, sometimes on the
client side.

In order to use it on the Client Side, I just add:
<script language="JavaScript" src="/js-lib/Conversion.js"></script>

But I can't use the same file AS-IS because the ASP statement
<!--#INCLUDE VIRTUAL="/js-lib/Conversion.js"-->

simply dumps the content of the file to the browser and doesn't interpret it
as JScript code because there are no <% %> tags in the file.

I don't want to have to maintain two identical files if I can help it.  Any
ideas?

Francois L.



Sat, 14 Sep 2002 03:00:00 GMT  
 JScript code for both server side and client side
Use the runat attribute.
Example:
<script language="JavaScript" src="/js-lib/Conversion.js"
runat="server"></script>
I hope this helps.
-Don


Quote:
> I'm trying to have only one file that contains the JScript code that can
be
> used on both the server side ASP pages and the client side HTML page.  The
> file contains functions to do conversion from Metric to Imperial and back.
> Sometimes I want to use the function on the server side, sometimes on the
> client side.

> In order to use it on the Client Side, I just add:
> <script language="JavaScript" src="/js-lib/Conversion.js"></script>

> But I can't use the same file AS-IS because the ASP statement
> <!--#INCLUDE VIRTUAL="/js-lib/Conversion.js"-->

> simply dumps the content of the file to the browser and doesn't interpret
it
> as JScript code because there are no <% %> tags in the file.

> I don't want to have to maintain two identical files if I can help it.
Any
> ideas?

> Francois L.



Sat, 14 Sep 2002 03:00:00 GMT  
 JScript code for both server side and client side
Actually, I forgot to mention that I tried that and it didn't work.  I have
a ASP page that has an #INCLUDE that works fine.  I can call the JScript
function defined within the included file.  My assumption was that replacing
the #INCLUDE with a <script language="JavaScript"
src="/js-lib/Conversion.js"></script> would work just the same, but it
doesn't.

My suspicion right now is that you can't use the SRC attribute when you have
RUNAT=SERVER.  Can anyone confirm/deny this?

Thanks,

Francois L.


Quote:
> Use the runat attribute.
> Example:
> <script language="JavaScript" src="/js-lib/Conversion.js"
> runat="server"></script>
> I hope this helps.
> -Don



> > I'm trying to have only one file that contains the JScript code that can
> be
> > used on both the server side ASP pages and the client side HTML page.
The
> > file contains functions to do conversion from Metric to Imperial and
back.
> > Sometimes I want to use the function on the server side, sometimes on
the
> > client side.

> > In order to use it on the Client Side, I just add:
> > <script language="JavaScript" src="/js-lib/Conversion.js"></script>

> > But I can't use the same file AS-IS because the ASP statement
> > <!--#INCLUDE VIRTUAL="/js-lib/Conversion.js"-->

> > simply dumps the content of the file to the browser and doesn't
interpret
> it
> > as JScript code because there are no <% %> tags in the file.

> > I don't want to have to maintain two identical files if I can help it.
> Any
> > ideas?

> > Francois L.



Sat, 14 Sep 2002 03:00:00 GMT  
 JScript code for both server side and client side
I assume that the .js file that you #INCLUDE contains <%...%> delimiters.  If you remove them then
can use the code on the client and the server

For the client:
<script language="JavaScript" src="/js-lib/Conversion.js"></script>

For the server:
<script language="JavaScript" src="/js-lib/Conversion.js" runat=server></script>

--
Michael Harris
MVP Scripting


Actually, I forgot to mention that I tried that and it didn't work.  I have
a ASP page that has an #INCLUDE that works fine.  I can call the JScript
function defined within the included file.  My assumption was that replacing
the #INCLUDE with a would work just the same, but it
doesn't.

My suspicion right now is that you can't use the SRC attribute when you have
RUNAT=SERVER.  Can anyone confirm/deny this?

Thanks,

Francois L.


Quote:
> Use the runat attribute.
> Example:
> <script language="JavaScript" src="/js-lib/Conversion.js"
> runat="server"></script>
> I hope this helps.
> -Don



> > I'm trying to have only one file that contains the JScript code that can
> be
> > used on both the server side ASP pages and the client side HTML page.
The
> > file contains functions to do conversion from Metric to Imperial and
back.
> > Sometimes I want to use the function on the server side, sometimes on
the
> > client side.

> > In order to use it on the Client Side, I just add:
> > <script language="JavaScript" src="/js-lib/Conversion.js"></script>

> > But I can't use the same file AS-IS because the ASP statement
> > <!--#INCLUDE VIRTUAL="/js-lib/Conversion.js"-->

> > simply dumps the content of the file to the browser and doesn't
interpret
> it
> > as JScript code because there are no <% %> tags in the file.

> > I don't want to have to maintain two identical files if I can help it.
> Any
> > ideas?

> > Francois L.



Sat, 14 Sep 2002 03:00:00 GMT  
 JScript code for both server side and client side
I hear you can use SRC and RUNAT=SERVER on IIS 5 (Windows 2000) but not IIS
4.

James

Quote:
> My suspicion right now is that you can't use the SRC attribute when you
have
> RUNAT=SERVER.  Can anyone confirm/deny this?

> Thanks,

> Francois L.



Sun, 15 Sep 2002 03:00:00 GMT  
 JScript code for both server side and client side
You're right...

A snip from "What's New in ASP"

"[...]You can now use the HTML <SCRIPT></SCRIPT> tag's SRC attribute to do server-side includes.
When you use the SRC attribute to specify a virtual or relative path, and use the RUNAT=SERVER
attribute to denote server-side execution, you can achieve the same functionality as the #Include
directive. [...]"

What's New in ASP
http://msdn.microsoft.com/library/psdk/iisref/iiwanew.htm

--
Michael Harris
MVP Scripting

I hear you can use SRC and RUNAT=SERVER on IIS 5 (Windows 2000) but not IIS
4.

James

Quote:
> My suspicion right now is that you can't use the SRC attribute when you
have
> RUNAT=SERVER.  Can anyone confirm/deny this?

> Thanks,

> Francois L.



Sun, 15 Sep 2002 03:00:00 GMT  
 JScript code for both server side and client side
On Tue, 28 Mar 2000 14:27:24 -0600, "Francois Lachance"

Quote:

>I'm trying to have only one file that contains the JScript code that can be
>used on both the server side ASP pages and the client side HTML page.  The
>file contains functions to do conversion from Metric to Imperial and back.
>Sometimes I want to use the function on the server side, sometimes on the
>client side.

>In order to use it on the Client Side, I just add:
><script language="JavaScript" src="/js-lib/Conversion.js"></script>

>But I can't use the same file AS-IS because the ASP statement
><!--#INCLUDE VIRTUAL="/js-lib/Conversion.js"-->

>simply dumps the content of the file to the browser and doesn't interpret it
>as JScript code because there are no <% %> tags in the file.

>I don't want to have to maintain two identical files if I can help it.  Any
>ideas?

>Francois L.

a=fs.OpenTextFile(Server.mappath("/js-lib/Conversion.js"),1,1);
if(!a.AtEndOfStream) result=a.ReadAll();
a.Close();
eval(result);

--
/* ************************************************************************** *\

**** Senior Technologist (http://www.or.interactive-media.com/users/nlilavois/)
**** Interactive Media   (http://www.interactive-media.com/)
**** 12605 Challenger Parkway, Suite 130, Orlando, FL 32826-3256
\* ************************************************************************** */



Mon, 16 Sep 2002 03:00:00 GMT  
 JScript code for both server side and client side
Sorry, the server side use of runat="server' is new to IIS5/ASP3...

--
Michael Harris
MVP Scripting

I assume that the .js file that you #INCLUDE contains <%...%> delimiters.  If you remove them then
can use the code on the client and the server

For the client:
<script language="JavaScript" src="/js-lib/Conversion.js"></script>

For the server:
<script language="JavaScript" src="/js-lib/Conversion.js" runat=server></script>

--
Michael Harris
MVP Scripting


Actually, I forgot to mention that I tried that and it didn't work.  I have
a ASP page that has an #INCLUDE that works fine.  I can call the JScript
function defined within the included file.  My assumption was that replacing
the #INCLUDE with a would work just the same, but it
doesn't.

My suspicion right now is that you can't use the SRC attribute when you have
RUNAT=SERVER.  Can anyone confirm/deny this?

Thanks,

Francois L.


Quote:
> Use the runat attribute.
> Example:
> <script language="JavaScript" src="/js-lib/Conversion.js"
> runat="server"></script>
> I hope this helps.
> -Don



> > I'm trying to have only one file that contains the JScript code that can
> be
> > used on both the server side ASP pages and the client side HTML page.
The
> > file contains functions to do conversion from Metric to Imperial and
back.
> > Sometimes I want to use the function on the server side, sometimes on
the
> > client side.

> > In order to use it on the Client Side, I just add:
> > <script language="JavaScript" src="/js-lib/Conversion.js"></script>

> > But I can't use the same file AS-IS because the ASP statement
> > <!--#INCLUDE VIRTUAL="/js-lib/Conversion.js"-->

> > simply dumps the content of the file to the browser and doesn't
interpret
> it
> > as JScript code because there are no <% %> tags in the file.

> > I don't want to have to maintain two identical files if I can help it.
> Any
> > ideas?

> > Francois L.



Mon, 16 Sep 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Help converting server-side VBScript array into client-side JScript array

2. Jscript client-side and server-side objects

3. getting server side vbscript array to client side jscript

4. getting server side vbscript array to client side jscript

5. Client-Side vs Server-side ASP/JScript

6. Calling Server Side JScript from Server Side VBScript

7. store server-side array in client side

8. Client-side Subroutine calling Server-Side Subroutine

9. pass server side vbscript to client side javascript

10. Client side VS server side

11. Client Side + Server Side Scripts

12. Client side scripting / server side scripting

 

 
Powered by phpBB® Forum Software