3

I have the following ASP.NET Literal Control displayed on my page

<div class="col-md-8 text-justify">
    <p>
        <asp:Literal ID="Literal1"
            Mode="PassThrough"
            Text= "<%#:Item.Description %>"          
            runat="server">
        </asp:Literal>

    </p> 
</div> 

This control is bound to a field in my SQL Server Table and a column called Description in the table contains the text with HTML tags like <p> <ul> <br> etc.

However when the text is displayed in the Literal control, it is displayed as-is i.e the HTML does not get rendered.

If the Literal control does not support rendering, what other options do I have?

1 Answer 1

6

Your problem isn't with the Literal control. It's the way you embedded the HTML. Try this:

<asp:Literal ID="Literal1"
        Mode="PassThrough"
        Text= "<%# Item.Description %>"          
        runat="server">
    </asp:Literal>

Notice I left out the colon? That colon is there to prevent injection attacks, where the contents of the value being embedded might come from a user. But if you trust the HTML content, then removing the colon will embed the HTML and allow it to render properly instead of escaping it.

Sign up to request clarification or add additional context in comments.

1 Comment

<%# Item.Description %> not the same <%#:Item.Description %> The colon : is the key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.