开发者

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

Like the preview box below that take input from the开发者_StackOverflow 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?


I would use the literal control unless you need to do anything "extra" with the 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜