Error on call to GetDocument

Last post 04-20-2010, 11:43 AM by Incognitobe. 6 replies.
Sort Posts: Previous Next
  •  04-16-2010, 10:44 AM 60178

    Error on call to GetDocument

    Hello Everyone,
     
    I´m trying to attach an event handler to the editor like it is shown in the demo:
     
    var editor1 = document.getElementById('CE_ctl00_mcp_te_editor_ID');
    var editdoc=editor1.GetDocument();
    [...]
     
    On the second Line an error occurs: "Object doesn’t support this property or method ". 
     
     The code runs inside a function which is execute in the window.onload event handler, so all the controls should be there.
     
    I´ve seen some posts in this forum concerning the same problem, but there never was a solution. The error occurred in  Version 6.0 so I upgraded to v6.6 but the result is the same.
     
    The Editor resides inside an ascx (.NET Control) which itself is embedded in an aspx-Page (surprise!). I´m using IE8.
     
    Does anybody know what I can do to resolve this Problem?
     
    Thanks a lot,
    Tobias
     
  •  04-16-2010, 2:47 PM 60184 in reply to 60178

    Re: Error on call to GetDocument

    Tobias,
     
    The problem is caused by you are using the wrong ID.
     
    Please user browser's view source function to search the ID of editor.
     
    'ClientID':'CE_Editor1_ID'

    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

  •  04-19-2010, 2:49 AM 60208 in reply to 60184

    Re: Error on call to GetDocument

    Hi Adam,
     
    thanks for the reply which sounds quite plausible and would certainly explain the error I´m getting, but I´m quite sure I got the ID right. Here´s a snippet from the html source of the table rendered by the editor (I omitted the style attribute):
     
    <table cellspacing="0" cellpadding="0" _IsCuteEditor="True" id="CE_ctl00_mcp_te_editor_ID" >
     
    and here is the part, where the initialize-method is called:
     
    <img [snip] onload="window.CuteEditorInitialize('CE_ctl00_mcp_te_editor_ID',{'_ClientID':'CE_ctl00_mcp_te_editor_ID' [snip] />
     
    so the ID does not seem to be the Problem.
     
    The Page containing the Editor is also containing a ScriptManager control which is used for several ajax-enabled features throughout the page. Might that have something to do with it?
     
    Thanks,
    Tobias
  •  04-19-2010, 11:01 PM 60235 in reply to 60208

    Re: Error on call to GetDocument

    Incognitobe:
    Hi Adam,
     
    thanks for the reply which sounds quite plausible and would certainly explain the error I´m getting, but I´m quite sure I got the ID right. Here´s a snippet from the html source of the table rendered by the editor (I omitted the style attribute):
     
    <table cellspacing="0" cellpadding="0" _IsCuteEditor="True" id="CE_ctl00_mcp_te_editor_ID" >
     
    and here is the part, where the initialize-method is called:
     
    <img [snip] onload="window.CuteEditorInitialize('CE_ctl00_mcp_te_editor_ID',{'_ClientID':'CE_ctl00_mcp_te_editor_ID' [snip] />
     
    so the ID does not seem to be the Problem.
     
    The Page containing the Editor is also containing a ScriptManager control which is used for several ajax-enabled features throughout the page. Might that have something to do with it?
     
    Thanks,
    Tobias
     
    Hi Tobias,
     
    Please try this example on your site.
     
    1. <%@ Page Language="C#" %>   
    2.   
    3. <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>   
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    5. <html xmlns="http://www.w3.org/1999/xhtml">   
    6. <head runat="server">   
    7.     <title>Untitled Page</title>   
    8. </head>   
    9. <body>   
    10.     <form id="form1" runat="server">   
    11.         <CE:Editor ID="Editor1" runat="server">   
    12.         </CE:Editor>   
    13.         <input type="button" value="Change Color" onclick="changeColor()" />   
    14.     </form>   
    15. </body>   
    16. </html>   
    17.   
    18. <script>   
    19. var editor1=document.getElementById("<%= Editor1.ClientID %>");   
    20.   
    21. function changeColor()   
    22. {   
    23. var editdoc = editor1.GetDocument();   
    24. editdoc.body.style.backgroundColor="Red";   
    25. }   
    26.   
    27. </script>  

    Regards,
     
    Ken
  •  04-20-2010, 3:59 AM 60242 in reply to 60235

    Re: Error on call to GetDocument

    Hi Ken,
     
    your example works great on my site, as long as I call 'changeColor' in the onclick event.
     
    Now let´s say that I want the editor to change color automatically, once the page has loaded. I would try to attach the function call to the onload event of the window, like this:
     
    <script>
    var editor1 = document.getElementById("<%= Editor1.ClientID %>");  
     
    function changeColor()   
    {   
    var editdoc = editor1.GetDocument();   
    editdoc.body.style.backgroundColor="Red";
    }

    window.onload = changeColor;
    </script>
     
    Voilá: "Object doesn’t support this property or method " on 'editor.GetDocument()'.
     
    This suggests that the editor isn't completely loaded, when the window.onload event occurs. My original mission was to call a certain function whenever the editor content changes. Is there any other way to wire the editor change event, if I can´t do it in the onload event of the window?
     
    Thanks,
    Tobias
     
     
     
  •  04-20-2010, 9:48 AM 60250 in reply to 60242

    Re: Error on call to GetDocument

    Tobias,
     
    Please try load the above Javascript code in Editor.AddInitializeScriptCode function.
     
    Demo:
     

    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

  •  04-20-2010, 11:43 AM 60257 in reply to 60250

    Re: Error on call to GetDocument

    Hi Adam,
     
    thanks a lot, works like a charm.
     
    It´s not exactly detailed in the Demo you referred me to but it wasn´t too hard to figure out the rest based on the hints you gave me.
     
    For anyone facing a similar problem, sticking to the example given in this thread, here´s what to do to make the editor change color once it finishes loading:
     
    Create a page according to the example given by Kenneth.
    Now add this piece of code to the code-behind:
     
    protected void Page_Load(object sender, EventArgs e)
     {
        Editor1.AddInitializeScriptCode("new function(){changeColor();}");
     }
     
     Once the editor finishes loading, the 'changeColor'-function will be called.
     
    Thanks again to all contributors,
    Tobias
     
     
View as RSS news feed in XML