when I use verifySpelling function, if click more times will report a error, please reference aaaaaa.jpg.
and the counter is not correct, if input 1 character, the count of text still 0, if paste, it could not calutute the correct count,
would you please help me to point out the error of force spelling and the correct remain character ??
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="radE" Namespace="Telerik.WebControls" Assembly="RadEditor.NET2" %>
<%@ Register TagPrefix="radS" Namespace="Telerik.WebControls" Assembly="RadSpell.NET2" %>
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<script type="text/javascript">
function checkSpelling() {
var editor = $find("<%=RadEditor1.ClientID %>"); //get reference to RadEditor's instance
editor.fire("AjaxSpellCheck"); //execute the RadEditor's command "AjaxSpellCheck"
editor.add_spellCheckLoaded(function () {
var spell = editor.get_ajaxSpellCheck(); //get a reference to RadEditor's SpellCheck
//save the content and submit the form when the spellchecker ends
spell.add_spellCheckEnd(function (sender, args) {
editor.saveContent(); //save the content before submission
document.forms[0].submit(); //submit the form
});
});
}
</script>
<script type="text/javascript">
var spellCheckFinished = false;
function verifySpelling() {
if (spellCheckFinished == true)
return;
var spell = GetRadSpell('<%= RadSpell1.ClientID %>');
spell.AttachEvent("OnClientCheckFinished", "checkFinished");
spell.StartSpellCheck();
return false;
}
function checkFinished(sender, args) {
spellCheckFinished = true;
args.SuppressCompleteMessage = true;
setTimeout('MySubmit();', 100);
}
function MySubmit() {
document.forms[0].submit();
}
</script>
<script type="text/javascript">
var maxTextLength = 20;
var messageText = 'You are not able to type more than ' + maxTextLength + ' symbols!';
function isAlphaNumericKey(keyCode) {
if ((keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91) || (keyCode == 32)) {
return true;
}
return false;
}
function LimitCharacters(editor) {
editor.AttachEventHandler("onkeydown", function (e) {
e = (e == null) ? window.event : e;
textLength = editor.GetText().length;
document.getElementById("counter").innerHTML = textLength;
if (isAlphaNumericKey(e.keyCode)) {
textLength = editor.GetText().length;
document.getElementById("counter").innerHTML = textLength;
if (textLength >= maxTextLength) {
alert(messageText);
e.returnValue = false;
return false;
}
}
});
editor.AttachEventHandler("onpaste", function (e) {
var textLength = CalculateLength(editor);
document.getElementById("counter").innerHTML = textLength;
if (textLength >= maxTextLength) {
alert(messageText);
e.returnValue = false;
e.cancelBubble = true;
return false;
}
});
}
function CalculateLength(editor) {
var textLength = editor.GetText().length;
var clipboardLength = window.clipboardData.getData("Text").length;
textLength += clipboardLength;
return textLength;
}
function OnClientCommandExecuting(editor, commandName, oTool) {
if (commandName == "PasteFromWord"
|| commandName == "PasteFromWordNoFontsNoSizes"
|| commandName == "PastePlainText"
|| commandName == "PasteAsHtml"
|| commandName == "Paste") {
if (document.all) {
var textLength = CalculateLength(editor);
if (textLength >= maxTextLength) {
alert(messageText);
return false;
}
}
}
}
</script>
<form id="form1" runat="server">
<table width="700px" border="0px">
<tr>
<td colspan="2">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" />
</td>
</tr>
<tr>
<td class="title" width="500px">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="RadEditor1"
ErrorMessage="Message is required."
Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValidator2" runat="server" EnableClientScript="false"
ErrorMessage="The message body should not be longer than the maxium number of characters."
ControlToValidate="RadEditor1" OnServerValidate="RadEditor1_Validate" Display="Dynamic" >*</asp:CustomValidator>
Message:
</td>
<td align="right">
<span id="counter"></span> Characters Left
</td>
</tr>
<tr>
<td colspan="2">
<radE:RadEditor ID="RadEditor1" runat="server" ToolsFile="ToolsFile.xml"
SpellDictionaryLanguage="en-US"
SpellCheckProvider="EditDistanceProvider" SpellEditDistance="2"
ShowHtmlMode="false" ShowPreviewMode="false"
ShowSubmitCancelButtons ="false"
OnClientCommandExecuting="OnClientCommandExecuting"
OnClientLoad="LimitCharacters"
Skin="WebBlue" Height="200px" Width="700px">
</radE:RadEditor>
<radS:RadSpell ID="RadSpell1" runat="server" ControlToCheck="RadEditor1"></radS:RadSpell>
<hr />
</td>
</tr>
<tr>
<td colspan="2" align="right">
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" OnClick="btnCancel_Click"/>
<asp:Button ID="btnNext" runat="server" Text="Next" onclientclick="verifySpelling();return false;" OnClick="btnNext_Click"/>
</td>
</tr>
</table>
</form>
</body>
</html>