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

Posted on 2011-04-20
Last Modified: 2012-05-11
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?


Question by:digital_soul
    LVL 3

    Accepted Solution

    There were syntax error in your statement. Try below corrected statement.

    Text='<%# Eval("Text").ToString().Replace(vbCrLf,"<br />") %>'
    LVL 2

    Assisted Solution

    try with () :

    Text='<%# Eval("Text").ToString().Replace(vbCrLf,"<br />") %>'
    LVL 21

    Expert Comment

    by:Alpesh Patel
    Please replace this part in dataset from where you are getting from.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Title # Comments Views Activity
    Ajax and MVC 2 52
    iTextSharp resize image 2 27
    Effect on button 11 39
    Adding WebGrid Checkbox Column checked by default 3 10
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now