Currently, I'm in the process of developing Javascript code for an ASP.net page.
Within my coding framework, the string "foo" is linked to a string variable called myString
.
In order to transfer the value of myString
to a JavaScript variable, I include the following lines of ASP.net code:
<script type='txt/javascript' language='javascript'>
var stringFromDotNet = '<%=myString%>';
</script>
This method functions smoothly unless myString
consists of quotation marks or line breaks. In such cases, errors arise and the code fails to execute properly. Furthermore, it has come to my attention that the code is susceptible to various types of injection attacks.
Hence, I am seeking alternative approaches to effectively assign the value of myString
to a JavaScript variable.
An update: After experimenting with an ASP:Hidden field on a separate page, I have noticed that the values inside are encoded in HTML.