title: Problems getting text into and out of ckeditor
body: <p>In our website we've created a process where admin users can change the text that appears in labels using the jQuery-UI dialog process that when they are in edit mode, clicking on a text area (label) brings up that text in a dialog box, they can change it, add a tooltip, and even a range of dates.  We decided that it would be great to be able to use ckeditor to be able to edit longer news items, or longer instruction labels.  Everything works except the actual taking the text to be edited from the database or taking the edited text in the ckeditor instance and saving it off to the database.  There is a lot of code, but for the mean time, I'll present the jQuery code to begin with, along with the .Net markup that generates the dialog box.  If this code looks OK to everyone I'll post more of the behind the scenes code.</p>
  
  <pre><code>$(function () {
  $("#dialog-markup").dialog(
  {
      autoOpen: false,
      height: 600,
      width: 600,
      modal: true,
      buttons:
      {
          "Save": function () {
              var GuiText = $(".gui_markup_text").val();
              if (GuiText == "")
                  GuiText == "&amp;nbsp;";
  
              var GuiToolTipText = $(".gui_markup_tooltip").val();
              if (GuiToolTipText == "")
                  GuiToolTipText == "&amp;nbsp;";
  
              editableControl[0].innerHTML = GuiText;
  
              var guiKey = "";
              if ($(editableControl).attr('gui_key') != null)
                  guiKey = $(editableControl).attr('gui_key');
              else
                  guiKey = $(editableControl).attr('id');
  
              var MarkupGui = new Object();
  
              MarkupGui.key = guiKey;
              MarkupGui.levels = $('input.hidden_Levels').val();
              MarkupGui.effectiveDate = $('.gui_markup_date_eff').val();
              MarkupGui.terminationDate = $('.gui_markup_date_trm').val();
              MarkupGui.textValue = GuiText;
              MarkupGui.toolTip = GuiToolTipText;
              //MarkupGui.hidden = hidFlag
  
              var DTO = { 'mg': MarkupGui };
  
              $.ajax({
                  type: "POST",
                  url: "GuiConfigWS.asmx/SaveMarkupToDB",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  data: JSON.stringify(DTO),
                  success: AjaxSuccess,
                  error: AjaxFailure
              }); //end of ajax call
  
              $(this).dialog("close");
              return false;
          },
          "Cancel": function () {
              $(this).dialog("close");
          } //End of Cancel button
      } //end of buttons
  }); //end of dialog
  </code></pre>
  
  <p>});    //end of markup anonymous function</p>
  
  <p>The key and hidden_levels are values that get saved in our database to identify which label this is for and what area's to apply it to.  The Key code is for those cases where we have asp.net controls versus standard html controls.  We use the id for a span as the key value in the database.  On Asp.net controls we add an attribute called "gui_key" which acts like the id.</p>
  
  <p>We have similar code that just creates a simple text string that can be edited and it works like a charm.  You can even add tags to that text, but we'd prefer to let users use ckeditor instead of having to "know" html tags for special formating.</p>
  
  <p>The .net markup follows for creating the dialog box:</p>
  
  <pre><code>&lt;div id="dialog-markup" class="markup" title="Edit Formated Text"&gt;
          &lt;p&gt;Use this editor below to add formated text.&lt;/p&gt;
          &lt;label id="lbl_Markup" for="txt_Markup"&gt;Formated Text: &lt;/label&gt;&lt;br /&gt;
          &lt;CKEditor:CKEditorControl ID="txt_Markup" CssClass="data gui_markup_text" runat="server" Toolbar="Source|Bold|Italic|Underline|Strike|-|Subscript|Superscript
                  Cut|Copy|Paste|PasteText|PasteFromWord
                  Undo|Redo|-|Find|Replace|-|RemoveFormat
                  NumberedList|BulletedList|-|Outdent|Indent|Table
                  /
                  JustifyLeft|JustifyCenter|JustifyRight|JustifyBlock
           Styles|Format|Font|FontSize|TextColor|BGColor"&gt;&lt;/CKEditor:CKEditorControl&gt;
          &lt;label id="lbl_MarkupEffDate" for="txt_MarkupEffDate"&gt;Start Date: &lt;/label&gt;
          &lt;input id="txt_MarkupEffDate" type="text" name="Eff_Date" class="dateField data gui_markup_date_eff" /&gt;&lt;br /&gt;
          &lt;label id="lbl_MarkupTrmDate" for="txt_MarkupTrmDate"&gt;End Date: &lt;/label&gt;
          &lt;input id="txt_MarkupTrmDate" type="text" name="Trm_Date" class="dateField data gui_markup_date_trm"/&gt;&lt;br /&gt;
          &lt;label id="lbl_MaarkupToolTip" for="txt_MarkupToolTip"&gt;Tool Tip: &lt;/label&gt;
          &lt;input id="txt_MarkupToolTip" type="text" name="ToolTip" class="gui_markup_tooltip" /&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>I'll add more code in follow up posts, for the GuiConfigWS.asmx webservice, for an example call to this, and for the class that handles the process.</p>
  
  <p>Here is an example of it being used in the code:</p>
  
  <pre><code>&lt;span id="info_Street1" class="editable markup" title="&lt;%= GetGuiToolTip("info_Street1")%&gt;"&gt;&lt;%= GetGuiString("info_Street1")%&gt;&lt;/span&gt;
  </code></pre>
  
  <p>Here is the GuiConfigWS.asmx:</p>
  
  <pre><code>&lt;%@ WebService Language="C#" Class="GuiConfigWS" %&gt;
  
  using System;
  using System.Web;
  using System.Web.Services;
  using System.Web.Services.Protocols;
  using System.Collections.Generic;
  using CKEditor;
  
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [System.Web.Script.Services.ScriptService]
  public class GuiConfigWS  : System.Web.Services.WebService 
  {
      public class MarkupGui
      {
          public string typeOfDialog { get; set; }
          public string key { get; set; }
          public string levels { get; set; }
          public string effectiveDate { get; set; }
          public string terminationDate { get; set; }
          public string textValue { get; set; }
          public string toolTip { get; set; }
      }
  
      [System.Web.Script.Services.ScriptMethod]
      [WebMethod(EnableSession = true)]
      public string SaveMarkupToDB(MarkupGui mg) //removed 'static' after public on Dave Ward's advice...
      {
          GuiConfig gc = new GuiConfig("[REDACTED - CONNECTION STRING INFO");
          gc.SetValue(mg.key, mg.levels, mg.effectiveDate, mg.terminationDate, mg.textValue, mg.toolTip, 0); //Convert.ToInt32(mg.hidden));
  
          return "testString";  //temp return until the rest of the code is written.
      } //end of SaveMarkupToDB
  </code></pre>
  
  <p>Again, we have another version that works completely.  I'm going to hold off adding the class that we use to do this stuff with, if you guys want to see it, post here and I'll post it.  But, it's very long and I think I'm pushing maximum density already...
  Thanks,
  Brad.</p>