I'm writing some Javascript code for an ASP.net page.
I have the string "foo" assigned to a string variable myString.
I would like to assign the value of myString to a JavaScript variable, so I write in my ASP.net code:
<script type='txt/javascript' language='javascript'>
var stringFromDotNet = '<%=myString%>';
</script>
This works fine as long as myString does not contain quotation marks or line-breaks, but as as soon as I try to assign something with quotation marks or line-breaks, all hell breaks loose and my code doesn't work. As a matter of fact, I can see that this code is vulnerable to all sort of injection attacks.
So... What can I do get the value of myString assigned to a variable in JavaScript?
Update: I've tried creating a page with just an ASP:Hidden field. It looks like the values inside are html encoded.