title: How do I stop HtmlEditorExtender encoding html in postback?
body: <p>I have a user control that contains a text box, an <code>HtmlEditorExtender</code>, and a button. The user control is loaded into a parent page using <code>LoadControl()</code>. Whenever I click on the button to post the form, any formatted text in the text box gets encoded, which is not what should happen.</p>
  
  <hr>
  
  <p>For example, if I load the text control with </p>
  
  <pre><code>&amp;lt;p&amp;gt;test&amp;lt;/p&amp;gt;
  </code></pre>
  
  <p>after I click on the button to post the page, the text returned by the <code>.Text</code> property is </p>
  
  <pre><code>&amp;amp;lt;p&amp;amp;gt;test&amp;amp;lt;/p&amp;amp;gt; 
  </code></pre>
  
  <p>If I post a second time, it is further encoded as: </p>
  
  <pre><code>&amp;amp;amp;lt;p&amp;amp;amp;gt;test&amp;amp;amp;lt;/p&amp;amp;amp;gt; 
  </code></pre>
  
  <p>and so on.</p>
  
  <hr>
  
  <p>I confirmed that the control works fine (does not encode the HTML) if I add the user control at design time to the page. This issue only happens if I use <code>LoadControl()</code> to load it.</p>
  
  <p>I have spent days trying to resolve this issue, but I just can't tell if I am doing something wrong, if the control is simply incompatible with this scenario, or if there is a reliable workaround.</p>
  
  <hr>
  
  <p>Here is a simple example:</p>
  
  <p>User control:</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestDynamicRichTextControl.ascx.cs" Inherits="Sample.forms.TestDynamicRichTextControl" %&gt; 
  &lt;asp:TextBox ID="txtBody" runat="server" Columns="80" Rows="15" TextMode="MultiLine"&gt;&lt;/asp:TextBox&gt; 
  &lt;ajaxToolkit:HtmlEditorExtender ID="heeBody" runat="server" TargetControlID="txtBody"&gt; 
      &lt;Toolbar&gt; 
          &lt;ajaxToolkit:Bold /&gt; 
          &lt;ajaxToolkit:Italic /&gt; 
          &lt;ajaxToolkit:Underline /&gt; 
      &lt;/Toolbar&gt; 
  &lt;/ajaxToolkit:HtmlEditorExtender&gt; 
  &lt;br /&gt; 
  &lt;asp:Button ID="btnTestPartialPostback" runat="server" Text="Test Partial Postback" onclick="btnTestPartialPostback_Click" /&gt; 
  &lt;asp:Label ID="lblResult" runat="server"&gt;&lt;/asp:Label&gt; 
  </code></pre>
  
  <p>User control code (<code>BaseUserControl</code> extends <code>System.Web.UI.UserControl</code> and declares <code>Initialize()</code>):</p>
  
  <pre><code>public partial class TestDynamicRichTextControl : BaseUserControl 
  { 
      protected void Page_Load(object sender, EventArgs e) 
      { 
      } 
  
      public override void Initialize() 
      { 
          txtBody.Text = "&lt;p&gt;test&lt;/p&gt;"; 
      } 
  
      protected void btnTestPartialPostback_Click(object sender, EventArgs e) 
      { 
          lblResult.Text = DateTime.Now.ToString(); 
      } 
  } 
  </code></pre>
  
  <p>The main page contains this placeholder:</p>
  
  <pre><code>&lt;asp:PlaceHolder ID="PlaceHolder1" runat="server"&gt;&lt;/asp:PlaceHolder&gt;
  </code></pre>
  
  <p>The code of the main page:</p>
  
  <pre><code>public partial class TestDynamicControl : System.Web.UI.Page 
  { 
      protected void Page_Load(object sender, EventArgs e) 
      { 
          PlaceHolder1.Controls.Clear(); 
          BaseUserControl formUc = (BaseUserControl)this.LoadControl("forms/TestDynamicRichTextControl.ascx"); 
          PlaceHolder1.Controls.Add(formUc); 
  
          if (!IsPostBack) 
              formUc.Initialize(); 
      } 
  } 
  </code></pre>