3

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.

Community
  • 1
  • 1
Tom Hamming
  • 10,577
  • 11
  • 71
  • 145
  • I'm seeing this problem using LoadControl ... you might check to see if your control is being loaded by another control. Using HtmlDecode as described below appears to be a good workaround. – Matthew Lowe Nov 01 '12 at 14:30

2 Answers2

2

Try to do like this,

myTxt.Text = HttpUtility.HtmlDecode(htmlStringFromDatabase);
0

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
xsari3x
  • 442
  • 2
  • 12
  • 36
  • This is pretty much exactly the same answer as was posted almost two years ago, and a duplicate of the answer you posted a couple minutes before this one. – Andrew Barber Jun 17 '14 at 21:32
  • @AndrewBarber the old answer didn't work , i checked it i was facing this problem and the route proposed in my answer solves this issue :) – xsari3x Jun 17 '14 at 21:34
  • Only the third line of your code is relevant to *this question*. If the other code you are posting fixed your issue, then your issue isn't related. – Andrew Barber Jun 17 '14 at 21:35
  • @AndrewBarber it fixed the issue of this questions which happens that I face it exactly , the old answer which is proposed two years ago will not solve the issue which is letting the HTMLExtender control to render an HTML from DB , my answer solves this – xsari3x Jun 17 '14 at 21:38
  • There is absolutely no `Literal` control in the question. The essence of your answer is "use `HtmlDecode()`", which is exactly what Saurav said before. – Andrew Barber Jun 17 '14 at 21:40
  • @AndrewBarber I used literal control is passthrough mode which will render the html then assigned it to the htmlextender , mmmm you can try both solutions ans see which one works – xsari3x Jun 17 '14 at 21:44
  • Alright, if you say so. `HtmlDecode` works fine, though. – Andrew Barber Jun 17 '14 at 21:45
  • Give it a try , htmldecode alone will only show the html in the control like "Test" , but using this route with Literal control will display "Test" bolded , I tried this my self :) also you will find similar questions with the same answer as Saurav answer and people say that this doesn't work – xsari3x Jun 17 '14 at 21:48