Problems getting text from editor

  •  09-08-2006, 9:12 AM

    Problems getting text from editor

    Usually I have no problem getting / setting the text of the editor.  I'm writing a custom button to switch the "mode" of the document from displaying it in cute editor to displaying the document in an HTML page.  Here is a snippet of my custom button:

    protected void Page_Load(object sender, EventArgs e)
    {
    WebControl ctrl2 = Editor1.CreateCommandButton("switchModesButton", "backward.gif", "Switch Modes");
    ctrl2.Attributes["onclick"] = "document.getElementById(\"Hidden1\").setAttribute(\"value\",\"switchModes\");document.forms[0].submit();";
    int pos2 = Editor1.ToolControls.IndexOf("Help") + 1;
    Editor1.InsertToolControl(pos2, "switchModesButton", ctrl2);

    if (Request.Form["Hidden1"].ToString().Equals("switchModes"))
    switchModes();
    }

    private void switchModes()
    {
    Session["editorContent"] = Editor1.XHTML;
    Response.Redirect("displayContent.aspx", false);
    }

    This code works fine except for the Editor1.XHTML part.  The user can load up their document and switch modes just fine.  However if the user makes any changes to the document they are lost in the transition and only the original text is transferred over to the displayContent.aspx page.  Am I doing something wrong?

    I tried another method to get the text from the editor but it did not work either.  I got this code from your website.  I set the onclick to just alert with the contents of the editor but it doesn't seem to do anything.  Here is a snippet of the non-working code pulled from your website:

    ctrl2.Attributes["onclick"] = "var editor1=document.getElementById('<%=Editor1.ClientID%>');var editdoc=editor1.GetDocument();alert(editdoc.body.innerHTML);";

    Any ideas?  Thanks!
View Complete Thread