0

I have an Html string which is stored in a Database . I fetch this string and try to render it through a literal control, but it is rendering the complete HTML code in that literal again. I have tried html encoding as well but it still fails.

My text Stored in Database is like this :

<p><b>Location. </b> <br />The Leela Palace Udaipur is a business-friendly property     located in Udaipur's Lake Pichola neighborhood, close to Lake Palace, Jag Niwas, and Jagdish Temple. Additional points of interest include City Palace and Crystal Gallery. </p>

But when I view the page it is same as above.

Please help me to find the solution. I am not using MVC

1
  • do you want to display it in a div? or any other HTML tag? Commented Sep 20, 2013 at 7:04

3 Answers 3

2

Best way, Use HttpUtility.HtmlEncode(this.Text).

Worked for me

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

Comments

1

Set the LiteralMode of your LiteralControl to PassThrough:

<asp:LiteralControl ID="yourHtml" runat="server" LiteralMode="PassThrough"></asp:LiteralControl>

From MSDN:

If you specify PassThrough, the entire contents of the Text property are passed to the device or browser without making any modifications

Warning: I hope you are confident of the HTML in the database that nothing malicious could ever creep in, because this is dangerous.

6 Comments

Again the Complete HTMl Rendered <asp:Literal ID="Literal5" runat="server" Text="<%#: Item.hotelDescription %>" Mode="PassThrough" />
again i got the same text : <p><b>Location. </b> <br />The Leela Palace Udaipur is a business-friendly property located in Udaipur's Lake Pichola neighborhood, close to Lake Palace, Jag Niwas, and Jagdish Temple. Additional points of interest include City Palace and Crystal Gallery. </p>
You might want to check Item.hotelDescription to see if it is already encoded
this is my database string : <p><b>Location. </b> <br />The Leela Palace Udaipur is a business-friendly property located in Udaipur's Lake Pichola neighborhood, close to Lake Palace, Jag Niwas, and Jagdish Temple. Additional points of interest include City Palace and Crystal Gallery. </p>
It is not encoded it directly coming from Linq : hbase.hotelDescription = hotel.PropertyDescription;
|
0

Look at Mode property of Literal.

3 Comments

Mode property value is transform
@jayeshbabel : Set the mode as 'PassThrough'
I have used a Placeholder and use DataBind Method.

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.