• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 568
  • Last Modified:

How can I retain linebreaks in a bound Literal control in Encode Mode?

Hi Experts

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?

Thanks

Stewart
0
digital_soul
Asked:
digital_soul
2 Solutions
 
Mrugesh1Commented:
There were syntax error in your statement. Try below corrected statement.

Text='<%# Eval("Text").ToString().Replace(vbCrLf,"<br />") %>'
0
 
gcitronCommented:
try with () :

Text='<%# Eval("Text").ToString().Replace(vbCrLf,"<br />") %>'
0
 
Alpesh PatelAssistant ConsultantCommented:
Please replace this part in dataset from where you are getting from.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now