1

Like the preview box below that take input from the textarea we are typing now.

The requirement is to retrieve HTML saved in database and preview it on the screen. Should I use label or is there any better control around?

3 Answers 3

4

I would use the literal control unless you need to do anything "extra" with the html.

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

1 Comment

asp.net literal is better control to render HTML
2

I often use a DIV with a runat="server" attribute declared. That way, I have a container to apply CSS classes to, and I know and can control the markup that is being created.

A Literal will work fine if you don't need a container (or you have a container already on the page).

<div class="css-class">
    <asp:Literal runat="server" />
</div>

OR

<div runat="server" class="css-class" />

And as Oded said, watch out for XSS by sanitizing your HTML.

Comments

1

If you simply need to output HTML, use a LiteralControl - you simply set its Text property to the HTML you need.

You may want to think about cleaning up the HTML, if it something that is user input, just in case of XSS attacks hiding in your HTML data.

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.