Here is the Simple Program and I can't get it to work. May be i am doing something wrong.
Please review this and let me know what am i doing wrong?
<%@ Page Language="C#" %>
<%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
<script language="javascript">
function AttachKeyBoardEvents(keyPressOnly)
{
var rtEditor = document.getElementById('<%=MessageEditor.ClientID%>');
var rtEditorDoc = rtEditor.GetDocument();
// attach Event
if(rtEditorDoc.attachEvent)
rtEditorDoc.attachEvent('onkeypress',HandleRTEKeyPress);
else if(rtEditorDoc.addEventListener)
rtEditorDoc.addEventListener('keypress',HandleRTEKeyPress,true);
if(keyPressOnly == undefined)
{
if(rtEditorDoc.attachEvent)
rtEditorDoc.attachEvent('onkeydown',HandleRTEKeyDown);
else if(rtEditorDoc.addEventListener)
rtEditorDoc.addEventListener('keydown',HandleRTEKeyDown,true);
}
}
function DetachKeyBoardEvents(keyPressOnly)
{
var rtEditor = document.getElementById('<%=MessageEditor.ClientID%>');
var rtEditorDoc = rtEditor.GetDocument();
// detach Event
if(rtEditorDoc.detachEvent)
rtEditorDoc.detachEvent('onkeypress',HandleRTEKeyPress);
else if(rtEditorDoc.removeEventListener)
rtEditorDoc.removeEventListener('keypress',HandleRTEKeyPress,true);
if(keyPressOnly == undefined)
{
if(rtEditorDoc.detachEvent)
rtEditorDoc.detachEvent('onkeydown',HandleRTEKeyDown);
else if(rtEditorDoc.removeEventListener)
rtEditorDoc.removeEventListener('keydown',HandleRTEKeyDown,true);
}
}
function HandleRTEKeyDown(e)
{
e = (e)?e:window.event;
var kCode = (e.keyCode)?e.keyCode:e.which;// gets the keycode in ie or ns
if(!e.ctrlKey && kCode == 13)
{
SendMessage();
return false;
}
}
function HandleRTEKeyPress(e)
{
e = (e)?e:window.event;
var kCode = (e.keyCode)?e.keyCode:e.which;// gets the keycode in ie or ns
if (e.ctrlKey && kCode == 10) { // Ctrl+Enter
var rtEditor = $($('MessageEditorCtrlID').value);
rtEditor.ExecCommand('break',false,'break');
}
}
function SendMessage()
{
var rtEditor = document.getElementById('<%=MessageEditor.ClientID%>');
var rtEditorDoc = rtEditor.GetDocument();
var rteText = rtEditorDoc.body.innerHTML;
if(rteText == '')
{
alert('Please enter text to send.');
return false;
}
document.getElementById('Message').innerHTML = rteText;
rtEditorDoc.body.innerHTML = '';//Set message to empty
//Set the Focus to RTE
rtEditor.FocusDocument();
//Reattach the Events
DetachKeyBoardEvents(true);
AttachKeyBoardEvents(true);
}
</script>
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr><td><div id="Message"></div></td></tr>
<tr><td><input type=button id="sendbutton" value="send" onclick="SendMessage();"/></td></tr>
</table>
<div>
<CE:Editor ID="MessageEditor" MaxHTMLLength="1000" Runat="server" Height="50%" Width="100%"
FilesPath="~/Cutesoft_Client/CuteEditor" AutoConfigure="Minimal" ShowHtmlMode="False" ShowPreviewMode="False" ShowBottomBar="False" ThemeType="OfficeXP">
</CE:Editor>
<script language=javascript>
AttachKeyBoardEvents();
</script>
</div>
</form>
</body>
</html>