How do I get this HTML to display formatted, without tags?

て烟熏妆下的殇ゞ 提交于 2019-12-01 09:17:57
nanonerd

FYI: The literal produced the same result as the Label ... but I got my answer, this works:

string strHTML = "<p>Hello World!</p>";
Label.Text = Server.HtmlDecode(strHTML);

Well the HTML is the formatting, so to get the text to display how you want you need to insert the text as HTML into your page rather than inserting the text into the Label.Text - which will treat is as plain text and display all the markup.

So rather than create a Label use a Literal:

<asp:Literal runat="server" ID="EditorOutput">

Then in your page load:

protected void Page_Load(object sender, EventArgs e)
{
    EditorOutput.Text = theText;
}

theText will be the string:

<p><strong>there was</strong> once a fox that lived</p> <p> in the<span style="color: #ff0000"> woods</span></p>

as read from your database.

If your string has been Encoded you will have to call Server.HtmlDecode on it to make sure that any &lt; and &gt; codes are converted back to < and >.

Source

I didn't understand. Do you mean, when you check the post, you get something like:

<b>there was</b> once a fox that lived...

It's probably a good idea to save it in .html format, since RTFs were never meant for the internet. It also sounds like you don't need to use a database in the first place. XML is better for that kind of task.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!