Dynamic Creation of Javascript Code

G

Guest

Good Day Folks,

I'm trying to dynamically create some Javascript code. The simplest form of
my asp.net code is shown below. Seems the compiler doesn't like the string
constant "</script>".

Any way around this ?
Thanks in advance
/Serge


Contents of "colorscheme.vb"
---------------------------------

<script runat="server">
Sub CreateColorSchemeJava()
Response.write("<script language=""Javascript"">" & vbcrlf)
Response.write("</script>" & vbcrlf) ' Error generated here.
End Sub
</script>


Contents of Main ASPX script.

<%@ Page Explicit="True" Language="VB" Debug="true"%>
<!--#include file="ColorScheme.vb"-->

<html>
<head>
<title></title>
<%
CreateColorSchemeJava()
%>
</head>
<body>

</body>
</html>

Compiler Error
----------------

String constants must end with a double quote. Error Line 6

Line 4:
Line 5: Response.write("<script language=""Javascript"">" & vbcrlf)
Line 6: Response.write("</script>" & vbcrlf)
Line 7:
Line 8: End Sub
 
J

Jon Skeet [C# MVP]

Serge said:
Good Day Folks,

I'm trying to dynamically create some Javascript code. The simplest form of
my asp.net code is shown below. Seems the compiler doesn't like the string
constant "</script>".

Any way around this ?

A couple of ways:
1) Use a code-behind instead of including the file
2) Use "</scr" & "ipt>" instead of "</script>"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top