title: TinyMCE with AJAX (Update Panel) never has a value
body: <p>I wanted to use a Rich Text Editor for a text area inside an update panel.</p>
  
  <p>I found this post: <a href="http://www.queness.com/post/212/10-jquery-and-non-jquery-javascript-rich-text-editors" rel="nofollow noreferrer">http://www.queness.com/post/212/10-jquery-and-non-jquery-javascript-rich-text-editors</a> via this question: <a href="https://stackoverflow.com/questions/1207382/need-asp-net-mvc-rich-text-editor">Need ASP.Net/MVC Rich Text Editor</a> </p>
  
  <p>Decided to go with TinyMCE as I used it before in non AJAX situations, and it says in that list it is AJAX compatible. Alright I do the good ol' <code>tinyMCE.init({ //settings here });</code>
  Test it out and it disappears after doing a update panel update. I figure out from a question on here that it should be in the <code>page_load</code> function so it gets run even on async postbacks. Alright do that and the panel stays. However, upon trying to submit the value from my textarea, the text of it always comes back as empty because my form validator always says "You must enter a description" even when I enter text into it. This happens the first time the page loads and after async postbacks have been done to the page.</p>
  
  <p>Alright I find this <a href="http://www.dallasjclark.com/using-tinymce-with-ajax/" rel="nofollow noreferrer">http://www.dallasjclark.com/using-tinymce-with-ajax/</a> and <a href="https://stackoverflow.com/questions/699615/cant-post-twice-from-the-same-ajax-tinymce-textarea">Can&#39;t post twice from the same AJAX TinyMCE textarea</a>. I try to add this code into my page load function right after the tinyMCE.init. Doing this breaks all my jquery being called also in the page_load after it, and it still has the same problem.</p>
  
  <p>I am still pretty beginner to client side scripting stuff, so maybe I need to put the code in a different spot than page_load? Not sure the posts I linked weren't very clue on where to put that code.</p>
  
  <p>My Javascript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  var redirectUrl = '&lt;%= redirectUrl %&gt;';
  
  function pageLoad() {
  
      tinyMCE.init({
          mode: "exact",
          elements: "ctl00_mainContent_tbDescription",
          theme: "advanced",
          plugins: "table,advhr,advimage,iespell,insertdatetime,preview,searchreplace,print,contextmenu,paste,fullscreen",
          theme_advanced_buttons1_add_before: "preview,separator",
          theme_advanced_buttons1: "bold,italic,underline,separator,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink,separator,styleselect,formatselect",
          theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,separator,removeformat,cleanup,charmap,search,replace,separator,iespell,code,fullscreen",
          theme_advanced_buttons2_add_before: "",
          theme_advanced_buttons3: "",
          theme_advanced_toolbar_location: "top",
          theme_advanced_toolbar_align: "left",
          extended_valid_elements: "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
          paste_auto_cleanup_on_paste: true,
          paste_convert_headers_to_strong: true,
          button_tile_map: true
      });
  
      tinyMCE.triggerSave(false, true);
      tiny_mce_editor = tinyMCE.get('ctl00_mainContent_tbDescription');
      var newData = tiny_mce_editor.getContent();
      tinyMCE.execCommand('mceRemoveControl', false, 'your_textarea_name');
  
      //QJqueryUI dialog stuff
  }&lt;/script&gt;
  </code></pre>
  
  <p>Now my current code doesn't have the <code>tinyMCE.execCommand("mceAddControl",true,'content');</code> which that one question indicated should also be added. I did try adding it but, again, wasn't sure where to put it and just putting it in the page_load seemed to have no effect.</p>
  
  <p>Textbox control:</p>
  
  <pre><code>&lt;asp:TextBox ID="tbDescription" runat="server" TextMode="MultiLine" 
                  Width="500px" Height="175px"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
  </code></pre>
  
  <p>How can I get these values so that the code behind can actually get what is typed in the textarea and my validator won't come up as saying it's empty? Even after async postbacks, since I have multiple buttons on the form that update it prior to actual submission.</p>
  
  <p>Thanks!</p>
  
  <p>Edit: For further clarification I have form validation on the back-end like so:</p>
  
  <pre><code>If tbDescription.Text = "" Or tbDescription.Text Is Nothing Then
          lblDescriptionError.Text = "You must enter a description."
          isError = True
      Else
          lblDescriptionError.Text = ""
      End If
  </code></pre>
  
  <p>And this error will always cause the error message to be dispalyed.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Alright I am getting desperate here, I have spent hours on this. I finally found what I thought to be a winner on experts exchange which states the following (there was a part about encoding the value in xml, but I skipped that): <a href="http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_25059848.html" rel="nofollow noreferrer">http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_25059848.html</a></p>
  
  <blockquote>
    <p>For anyone who wants to use tinyMCE with AJAX.Net:</p>
  </blockquote>
  
  <ol start="2">
  <li><p>Append begin/end handlers to the AJAX Request object.  These will remove the tinyMCE control before sending the data (begin), and it will recreate the tinyMCE control (end):</p>
  
  <pre><code>Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(function(sender, args) {
      var edID = "&lt;%=this.ClientID%&gt;_rte_tmce"; // the id of your textbox/textarea.
      var ed = tinyMCE.getInstanceById(edID);
    if (ed) {
      tinyMCE.execCommand('mceFocus', false, edID);
      tinyMCE.execCommand('mceRemoveControl', false, edID);
  }
      });
  
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(sender, args) {
       var edID = "&lt;%=this.ClientID%&gt;_rte_tmce";
        var ed = tinyMCE.getInstanceById(edID);
        if (ed) {
      tinyMCE.execCommand('mceAddControl', false, edID);
        }
     });
  </code></pre></li>
  <li><p>When the user changes/blurs from the tinyMCE control, we want to ensure that the textarea/textbox gets updated properly:</p>
  
  <pre><code>   ed.onChange.add(function(ed, l) {
         tinyMCE.triggerSave(true, true);
   });
  </code></pre></li>
  </ol>
  
  <p>Now I have tried this code putting it in its own script tag, putting the begin and end requests into their own script tags and putting the ed.onChange in the page_load, putting everything in the page_load, and putting all 3 in it's own script tag. In all cases it never worked, and even sometimes broke the jquery that is also in my page_load... (and yes I changed the above code to fit my page)</p>
  
  <p>Can anyone get this to work or offer a solution? </p>
  
  <p>The code </p>