Reputation: 21
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
Upvotes: 0
Views: 4419
Reputation: 78605
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.
Upvotes: 1