简体   繁体   中英

Is there such a control in ASP.NET that can render HTML during runtime?

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?

我将使用文字控件,除非您需要对HTML进行任何“额外”操作。

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM