Javascript – use a VB variable inside of an Embedded Javascript section

asp.netjavascriptvb.net

Is it possible to do something like this:

<% Dim foo as string = "bar" %>

<script type="text/javascript">
    var baz = <%=foo %>
</script>

Where the <script> tag is embedded on my index page?

Best Solution

Yes, but make sure you put quotes around it and a semicolon:

var baz = '<%=foo %>';