editor hidden by display=none, javascript GetDocument is not a function error

Last post 10-31-2009, 9:05 AM by Adam. 1 replies.
Sort Posts: Previous Next
  •  10-30-2009, 10:59 PM 56829

    editor hidden by display=none, javascript GetDocument is not a function error

    Hi
     
    I have a page with a Cute Editor that the user hides/shows via javascript (setting the <div style='display:none'> )
    The page must validate on the client side (even when the Editor is hidden) .
     But the line "editor.GetDocument()" fails if the editor is hidden.
    Any workaround ?
    Here's a stripped down version of the page. (It works if you remove the display:none)
     
     <script language="javascript" type="text/javascript">
        <!--
            function maxSizeEdit(source, args) {
                alert('<%= edit.ClientID %>');
                args.IsValid = valCuteEditorLength('<%= edit.ClientID %>', 10, 'My Editor');
            }

            function valCuteEditorLength(id, maxLength, controlToValidateName) {
                var editor = document.getElementById(id);
                var editdoc = editor.GetDocument();
                var editbody = editdoc.body;
                   
                var curLength;
                if (document.all)
                { curLength = editbody.innerText.length; }
                else
                { curLength = editbody.textContent.length; }
                
                if (curLength <= maxLength) {
                    return true;
                }
                else {
                    alert(controlToValidateName + ' exceeded ' + maxLength + ' characters');
                    return false;
                }
            }
        //-->
    </script>
          
        <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="sm"></asp:ScriptManager>
        <div>
            <asp:ValidationSummary runat="server" ID="valSummary" DisplayMode="List" ShowSummary="true" />
            <div style="display:none">
            <CE:Editor runat="server" ID="edit" ShowEditMode="False" ShowHtmlMode="False"
                ShowPreviewMode="False" Text="12456789012345"></CE:Editor>
            </div>    
            <asp:CustomValidator runat="server" ID="valEdit" ValidateEmptyText="true" ControlToValidate="edit" ClientValidationFunction="maxSizeEdit" ErrorMessage="Too Big" Text="*"></asp:CustomValidator>    
            
            <asp:Button runat="server" ID="btnOK" Text="OK" CausesValidation="true"/>
        </div>
        </form> 
     
  •  10-31-2009, 9:05 AM 56831 in reply to 56829

    Re: editor hidden by display=none, javascript GetDocument is not a function error

View as RSS news feed in XML