How to set HtmlEditorExtender's content server-side

血红的双手。 提交于 2019-12-13 14:16:41

问题


I'm using the AjaxControlToolkit's HtmlEditorExtender in my ASP.NET 4.0 web app:

<asp:TextBox ID="myTxt" runat="server" TextMode="MultiLine" Height="80px" Width="100%" />
<act:HtmlEditorExtender ID="heMyTxt" runat="server" TargetControlID="myTxt">
  <Toolbar>
    etc...
  </Toolbar>
</act:HtmlEditorExtender>

When I set the content of the text box server-side like this:

myTxt.Text = htmlStringFromDatabase;

...the content in the textbox is the literal HTML markup (i.e. <b>Bold</b> shows up just like that, not like Bold). The formatting doesn't transfer, but the Extender does do its work on the textbox and set up its toolbar and buttons, etc. Is there a different way to set the content?

EDIT: turns out the HTML I get out of myTxt (the control that the extender is attached to) is encoded HTML. So now the question is how to stop the control from encoding its content. This problem is also presented in this question, but I'm not using LoadControl() or the designer to my page; I've written my markup manually.

Also, I don't know if this makes a difference, but I'm pulling the text out of the TextBox in the page's Page_Load handler.


回答1:


Try to do like this,

myTxt.Text = HttpUtility.HtmlDecode(htmlStringFromDatabase);



回答2:


I was able to solve this problem like this :

        Literal lit = new Literal();
        lit.Mode = LiteralMode.PassThrough;
        lit.Text = HttpUtility.HtmlDecode(HTMLTExt);
        TextBox1.Text = lit.Text; // The text box which HTMLEditorExtender is attached to


来源:https://stackoverflow.com/questions/10957048/how-to-set-htmleditorextenders-content-server-side

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