How can I retain linebreaks in a bound Literal control in Encode Mode?
Posted on 2011-04-20
I am binding data from a database to a Literal Control with Mode set to Encode as the data is user generated, to ensure no script code can be rendered. Line breaks in the data are not being rendered and I need to be able to ensure they are.
Previously I would have done something like the following in a bound label Control
Text='<%# Eval("Text").ToString.Replace(vbCrLf,"<br />") %>'
But this is giving me the error '''object.ToString()' is a 'method', which is not valid in the given context"
Presumbaly any attempt to replace with a <br /> tag will not work anyway when the Mode is set to Encode, so how can i do it?