Problems getting text from editor

Last post 09-08-2006, 1:26 PM by Adam. 1 replies.
Sort Posts: Previous Next
  •  09-08-2006, 9:12 AM 22523

    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!
  •  09-08-2006, 1:26 PM 22542 in reply to 22523

    Re: Problems getting text from editor

    UnlnvlslblE,
     
    Change the following code:
     
    ctrl2.Attributes["onclick"] = "var editor1=document.getElementBy
    Id('<%=Editor1.ClientID%>');var editdoc=editor1.GetDocument();alert(editdoc.body.innerHTML);";
     
    to:
     
    ctrl2.Attributes["onclick"] = "var editor1=document.getElementById('"+Editor1.ClientID+"');alert(editor1.getHTML());";
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

View as RSS news feed in XML