2

I have some code stored in SQL database that is in from of HTML code For example in the database I have stored

<b>Lorem Ipsum</b>

When I retrieve that data from sql and input it into a label it shows something like

&lt;b&gtLorem Ipsum&lt;/b&gt;

but I want it to use html code so that formatting is available.

1
  • Then you have stored your html code as html_entities. This means that, when you output it on a webpage, the html code will be displayed and not rendered. I think your error is in the routine that stores the html in the db. Please show us that code, so we can help you fix it. Commented Jul 29, 2013 at 8:12

2 Answers 2

3

The Label control encodes whatever value you set it to. Don't use a Label, use a Literal instead.

<asp:Literal ID="litExample"></asp:Literal>

Then set it's Text property:

litExample.Text = "<b>Lorem Ipsum</b>";

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

Comments

0

You can use a span too:

<span runat="server" id="mySpan" />

Then set InnerHtml property:

mySpan.InnerHtml = [...];

Sometimes it's better to use System.Web.UI.HtmlControls instead of System.Web.UI.WebControls because they create a cleaner and smaller HTML output.

Comments

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.