Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 24, 2010 11:07 PM by superconsultant
Contributor
2428 Points
398 Posts
Aug 05, 2009 01:21 AM|LINK
Just move it from the <head runat="server">. I have improved the example:
<%@ Page Language="VB" AutoEventWireup="false" %> <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %> <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc2" %> <!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></title> </head> <body> <form id="form1" runat="server"> <div> <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </cc1:ToolkitScriptManager> <asp:UpdatePanel ID="updatePanel1" runat="server"> <ContentTemplate> <cc2:Editor ID="myEditor" runat="server"Height="400px" /> <asp:Button runat="server" Text="Submit content" ID="submit" /> <br /> <br /> <span> HTML:<input type="text" readonly="readonly" id="totalHtml" value=""/> Text:<input type="text" readonly="readonly" id="totalPlain" value=""/> </span> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> <script type="text/javascript"> // on Application load Sys.Application.add_load(function() { var editor = $find("<%= myEditor.ClientID %>"); // Editor's ID="myEditor" var editPanel = editor.get_editPanel(); var designPanel = editPanel.get_modePanels()[AjaxControlToolkit.HTMLEditor.ActiveModeType.Design]; editPanel._setActive_saved = editPanel._setActive; editPanel._setActive = function() { if (this.get_activeMode() == AjaxControlToolkit.HTMLEditor.ActiveModeType.Design) { var designPanel = this.get_activePanel(); designPanel.onContentChanged(); } this._setActive_saved(); }; designPanel.onContentChanged = function() { var innerText; if (AjaxControlToolkit.HTMLEditor.isIE) { innerText = this._doc.body.innerText; } else { var div1 = document.createElement("div"); var html = new AjaxControlToolkit.HTMLEditor.jsDocument(true); AjaxControlToolkit.HTMLEditor.__MozillaGetInnerText(div1, html); innerText = html.toString(); delete div1; delete html; } // HTML text length var htmlTextLength = AjaxControlToolkit.HTMLEditor.Trim(this._doc.body.innerHTML).length; // Plain text length var plainTextLength = innerText.replace(/^[\s]+/g, "").replace(/[\s]+$/g, "").replace(/[\s]+/g, " ").length; // Place here your code: document.getElementById("totalHtml").value = htmlTextLength; document.getElementById("totalPlain").value = plainTextLength; } }); </script> </html>
Member
262 Points
427 Posts
Aug 05, 2009 02:48 AM|LINK
obout_teo Just move it from the <head runat="server">. I have improved the example:
Bingo!! Works perfectly! Thank you, thank you, thank you!! I'm going to talk to my company about considering your products. Your support has been terrific. Thanks again.
John
383 Points
96 Posts
Aug 24, 2010 11:07 PM|LINK
I created the page exactly as you provided it, but unfortunately it still doesn't work for me, I get the following error:
Microsoft JScript runtime error: 'AjaxControlToolkit' is undefined
on this line:
var designPanel = editPanel.get_modePanels()[AjaxControlToolkit.HTMLEditor.ActiveModeType.Design];
Any suggestions?
obout_teo
Contributor
2428 Points
398 Posts
Re: Character counter with Editor control?
Aug 05, 2009 01:21 AM|LINK
Just move it from the <head runat="server">.
I have improved the example:
<%@ Page Language="VB" AutoEventWireup="false" %> <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %> <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc2" %> <!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></title> </head> <body> <form id="form1" runat="server"> <div> <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </cc1:ToolkitScriptManager> <asp:UpdatePanel ID="updatePanel1" runat="server"> <ContentTemplate> <cc2:Editor ID="myEditor" runat="server"Height="400px" /> <asp:Button runat="server" Text="Submit content" ID="submit" /> <br /> <br /> <span> HTML:<input type="text" readonly="readonly" id="totalHtml" value=""/> Text:<input type="text" readonly="readonly" id="totalPlain" value=""/> </span> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> <script type="text/javascript"> // on Application load Sys.Application.add_load(function() { var editor = $find("<%= myEditor.ClientID %>"); // Editor's ID="myEditor" var editPanel = editor.get_editPanel(); var designPanel = editPanel.get_modePanels()[AjaxControlToolkit.HTMLEditor.ActiveModeType.Design]; editPanel._setActive_saved = editPanel._setActive; editPanel._setActive = function() { if (this.get_activeMode() == AjaxControlToolkit.HTMLEditor.ActiveModeType.Design) { var designPanel = this.get_activePanel(); designPanel.onContentChanged(); } this._setActive_saved(); }; designPanel.onContentChanged = function() { var innerText; if (AjaxControlToolkit.HTMLEditor.isIE) { innerText = this._doc.body.innerText; } else { var div1 = document.createElement("div"); var html = new AjaxControlToolkit.HTMLEditor.jsDocument(true); AjaxControlToolkit.HTMLEditor.__MozillaGetInnerText(div1, html); innerText = html.toString(); delete div1; delete html; } // HTML text length var htmlTextLength = AjaxControlToolkit.HTMLEditor.Trim(this._doc.body.innerHTML).length; // Plain text length var plainTextLength = innerText.replace(/^[\s]+/g, "").replace(/[\s]+$/g, "").replace(/[\s]+/g, " ").length; // Place here your code: document.getElementById("totalHtml").value = htmlTextLength; document.getElementById("totalPlain").value = plainTextLength; } }); </script> </html>diverguy
Member
262 Points
427 Posts
Re: Character counter with Editor control?
Aug 05, 2009 02:48 AM|LINK
Bingo!! Works perfectly! Thank you, thank you, thank you!! I'm going to talk to my company about considering your products. Your support has been terrific. Thanks again.
John
superconsult...
Member
383 Points
96 Posts
Re: Character counter with Editor control?
Aug 24, 2010 11:07 PM|LINK
I created the page exactly as you provided it, but unfortunately it still doesn't work for me, I get the following error:
on this line:
var designPanel = editPanel.get_modePanels()[AjaxControlToolkit.HTMLEditor.ActiveModeType.Design];
Any suggestions?