kavitha vemula

kavitha vemula

  • NA
  • 13
  • 2.2k

How to get the ckeditor word count while typing

Feb 3 2017 2:57 AM

After typing some text in ckeditor i am able to see the word count on button click but i need to view the word count while typing only.How can i do this.

Below is my code which gives the word count on button click

<body>
<form id="form1" runat="server">
<div>
<CKEditor:CKEditorControl ID="CKEditor1" BasePath="/ckeditor/" runat="server">
</CKEditor:CKEditorControl>
<asp:Button ID="btn1" runat="server" OnClick="btn1_Click" Text="Get Word Count" />
<asp:Label ID="lbl1" runat="server"></asp:Label>
</div>
</form>
</body>

protected void Page_Load(object sender, EventArgs e)
{

}

protected void btn1_Click(object sender, EventArgs e)
{
string whole_text = CKEditor1.Text;
string trimmed_text = whole_text.Trim();

// new line split here
string[] lines = trimmed_text.Split(Environment.NewLine.ToCharArray());

// don't need this here now...
//string[] split_text = trimmed_text.Split(' ');

int space_count = 0;
string new_text = "";
foreach (string line in lines)
{
// Modify the inner foreach to do the split on ' ' here
// instead of split_text
foreach (string av in line.Split(' '))
{
if (av == "")
{
space_count++;
}
else
{
new_text = new_text + av + ",";
}
}
}

new_text = new_text.TrimEnd(',');

// use lines here instead of split_text
lines = new_text.Split(',');
//MessageBox.Show(lines.Length.ToString());
lbl1.Text = lines.Length.ToString();
}


Answers (2)