Click here to Skip to main content
16,018,458 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used HTML EDITOR in my page for Getting article from user. I need to count the no of characters entered by user on a editor..... And fix the total characters on a editor.....How can i do that?
Posted
Comments
Prasad Khandekar 28-May-13 6:46am    
Hello Checkout this thread on Asp.Net forums (http://forums.asp.net/t/1454098.aspx/2/10)

1 solution

XML
<%@ 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>


Don't forget to mark this post as answer, if it helped you...

Thanks

Happy Coding...
 
Share this answer
 
v2
Comments
SnvMohan 28-May-13 8:10am    
I have tried this but not working well ......The problems are arrived in update panel when i tried to create that
renish patel 28-May-13 8:15am    
for me its working fine... please recheck it...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900