How to register onKeyDown on the editing window?

Last post 10-24-2010, 9:49 PM by Kenneth. 4 replies.
Sort Posts: Previous Next
  •  06-27-2006, 2:55 PM 20533

    How to register onKeyDown on the editing window?

    We are looking at puchasing this product but need to be able to register a onKeyDown javascript event to the editing window.

    When I try Editor1.Attributes.Add("onKeyDown", "checkDeletion(this);"); it adds the keydown to the outer table of the editiing window not the window itself. Can someone here please point me in the right direction? Thanks in advance.

  •  06-27-2006, 3:00 PM 20534 in reply to 20533

    Re: How to register onKeyDown on the editing window?

    cbreier,
     
    Please check this example:
     
     
    Change the onKeyPress event in the example to OnKeyDown event.
     
    The source code of this example is included in the download package.
     
     

    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

  •  12-13-2007, 8:16 PM 35805 in reply to 20534

    Re: How to register onKeyDown on the editing window?

    Adam,
     
     
    Please check this again. It's not firing the OnChange event the first time the web page is loaded. We're having a lot of trouble in our app with this.
  •  10-22-2010, 5:46 AM 64628 in reply to 35805

    Re: How to register onKeyDown on the editing window?

    copied from another thread hopefully this will help,
     
    Thanks for your reply Adam. I'm already using that function 
     
    I talked with support and they told me to reproduce the error in an example page.
    Here is a simple test page showing the error, I want to focus on the editor after a tab on the textfield (not working well in this example, use "S" instead), and after the user press ctrl+tab on the cute editor I want the focus back into the text editor.
     
    When you press control tab inside the  cute editor I get an exception. I want just to get the focus back in the text field.
    Thanks for your help.
     
    Here is the test case, please give it a try.
     
     
    <%@ Page Language="C#" AutoEventWireup="true" %>
    <%@ Register TagPrefix="ce" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>



    <script type="text/jscript">
    var editor = null;



    function onBodyLoad(){

        document.getElementById("Text1").focus();
        window.setTimeout("iniCuteEditor()",1000);

    }
     

     function iniCuteEditor()
        {  
           editor = document.getElementById('<% = Editor.ClientID%>');     
           var editdoc=editor.GetDocument();
                // attach Event
            editdoc.attachEvent('onkeydown',cuteEditorOnkeyDown);
             document.getElementById("Text1").focus();
        }


    function cuteEditorOnkeyDown(e)
        {
                        
            if (event) e = event;    
            
            if (e.ctrlKey && e.keyCode == 9) //Tab+Ctrl?
            {    
             document.getElementById("Text1").focus();
            }    
                
            
        }

    function textKeyDown(){

        //debugger;
        if(event.keyCode == 9 || event.keyCode==83) //tab? or S
            {
                 editor = document.getElementById('<%=Editor.ClientID%>');
                editor.FocusDocument();
                event.cancelBubble =true;
                return false;
        
            }


    }

    </script>

    </head>

    <body onkeydown="" onload="onBodyLoad()">
        <form id="form1" runat="server">
        <div>
        
        test &nbsp;<input id="Text1" type="text" onkeydown="textKeyDown();" />
        <br/><br/>
        
        <CE:Editor id="Editor" runat="server" Width="720px" Height="250px" ShowBottomBar="false" UseHTMLEntities="true">
                </CE:Editor>
            <br />
            </div>
        </form>
    </body>
    </html>
  •  10-24-2010, 9:49 PM 64658 in reply to 64628

    Re: How to register onKeyDown on the editing window?

    Hi adviserlogic2011,
     
    Please try the example below. focus on editor window and press ctrl+a, the focus will back to textbox1.
     
    1. <%@ Page Language="C#" %>  
    2.   
    3. <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>  
    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 id="Head1" runat="server">  
    7.     <title>Untitled Page</title>  
    8. </head>  
    9. <body>  
    10.     <form id="form1" runat="server">  
    11.         <asp:TextBox ID="textBox1" runat="server"></asp:TextBox>  
    12.         <CE:Editor ID="editor1" runat="server">  
    13.         </CE:Editor>  
    14.     </form>  
    15. </body>  
    16. </html>  
    17.   
    18. <script>  
    19. var textBox1=document.getElementById("<%= textBox1.ClientID %>");  
    20.   
    21. function CuteEditor_OnInitialized(editor)     
    22. {     
    23.     var editwin = editor.GetWindow();     
    24.     var editdoc = editor.GetDocument();    
    25.     //for firefox   
    26.     if(window.addEventListener)     
    27.     {     
    28.           
    29.         editdoc.addEventListener("keydown",focusTextBox,"false");     
    30.     }     
    31.     //for ie  
    32.     editdoc.body.onkeydown=function()     
    33.     {     
    34.         //control+a back to textBox1  
    35.         if(editwin.event.ctrlKey&&editwin.event.keyCode==65)  
    36.             {  
    37.                  textBox1.focus();  
    38.             }  
    39.     }     
    40. }   
    41.   
    42. function focusTextBox(oEvent)  
    43. {  
    44.       //control+a back to textBox1  
    45.     if(oEvent.ctrlKey&&oEvent.keyCode==65)  
    46.     {  
    47.      textBox1.focus();  
    48.     }  
    49.       
    50. }  
    51. </script> 
     Regards,
     
    ken
View as RSS news feed in XML