Firefox problem: content of editor lost between Javascript/PasteHTML and ASP.NET?

Last post 04-10-2008, 6:46 PM by rockford. 1 replies.
Sort Posts: Previous Next
  •  04-09-2008, 9:06 PM 38976

    Firefox problem: content of editor lost between Javascript/PasteHTML and ASP.NET?

    The following basic Javascript logic (called by a button-click event added as an Attribute to a button on our ASP.NET form) works fine in IE, but not in Firefox (note: I needed to write a separate Javascript function to handle Firefox because 'selectedhtml' needed to be derived differently than in IE, per a response to an earlier post here).  
     
    The problem:  the alerts at the end of the function confirm that the editor1.getHTML() returns the expected content (original editor content plus the content from the PasteHTML statement), but upon arriving back at the ASP.NET module the content added by the PasteHTML is gone.  This was confirmed by a Visual Studio debugger session.   For Firefox, does some other statement (a save or the like) need to be added in order to make the changes to the editor added in Javascript 'stick'?  Thanks very much.
     
    function CE_Firefox_LineOutSelectionHTML()

    //For Firefox/Mozilla/Netscape

    {

    alert("DEBUG: Reached CE_Firefox_LineOutSelectionHTML");

    var editor1 = document.getElementById('<%=Editor1.ClientID%>');

    var editor1doc = editor1.GetDocument();

    var editwin = editor1.GetWindow();

    var selectedhtml = "";

        if (window.getSelection)

        {

         alert("DEBUG: CE_Firefox_LineOutSelectionHTML, window.getSelection");

         rng=editwin.getSelection();

        alert("DEBUG: CE_Firefox_LineOutSelectionHTML, rng=" + rng);

         if (rng.rangeCount > 0 && window.XMLSerializer)

         {

         rng=rng.getRangeAt(0);

         selectedhtml=new XMLSerializer().serializeToString(rng.cloneContents());

         alert("DEBUG: CE_Firefox_LineOutSelectionHTML, selectedhtml from rng=" + selectedhtml);

         }

        }

    // Grab selected text, store it in hidden field on form

    if (Trim(selectedhtml).length == 0)

    {

    alert("No text or image selected, update cancelled");

    return false;

    }

    else

    {

    document.Form1.txtHoldEditorSelection.value = selectedhtml;

    alert("DEBUG: CE_Firefox_LineOutSelectionHTML, txtHoldEditorSelection.value=" + document.Form1.txtHoldEditorSelection.value);

    document.Form1.txtHoldEditorSelectionType.value = "Text";

    alert("DEBUG: CE_Firefox_LineOutSelectionHTML, txtHoldEditorSelectionType.value=" + document.Form1.txtHoldEditorSelectionType.value);

    alert("DEBUG: CE_Firefox_LineOutSelectionHTML, verify editor1.getHTML before PasteHTML=" + editor1.getHTML());

        alert("DEBUG: CE_Firefox_LineOutSelectionHTML, verify selectedhtml before PasteHTML=" + selectedhtml);

    editor1.PasteHTML("**BEFORESELECTION**" + selectedhtml + "**AFTERSELECTION**");

    document.Form1.txtHoldEditorContent2.value = editor1.getHTML();

    // For Firefox, the text property was required here? (for IE, value was required?)

    document.Form1.txtHoldEditorContent2.text = editor1.getHTML();

    alert("DEBUG: CE_Firefox_LineOutSelectionHTML after PasteHTML/exiting editor1.getHTML=" + editor1.getHTML());

    alert("DEBUG: CE_Firefox_LineOutSelectionHTML after PasteHTML/exiting, Form Field txtHoldEditorContent2.text=" + document.Form1.txtHoldEditorContent2.text);

    alert("DEBUG: CE_Firefox_LineOutSelectionHTML after PasteHTML/exiting, Form Field txtHoldEditorContent2.value=" + document.Form1.txtHoldEditorContent2.value);

    return true;

    }

    }

  •  04-10-2008, 6:46 PM 39064 in reply to 38976

    Re: Firefox problem: content of editor lost between Javascript/PasteHTML and ASP.NET?

    Reposting to put back at the top of the queue, as all newer posts were replied to today.
View as RSS news feed in XML