I have added only limited text formatting option to WebHtmlEditor (See the attached image). This control is used for web site visitors to copy and paste texts from word documents or other text resources to this editor. I need to remove all the other text formatting which are not belongs to the WebHtmlEditor formatting options that are provided on control.
See the attached image: I want to remove other text colors, highlights...etc when the text getting saved in database.
Hello Aruna,
Let me know if this resolves your issue and if I can provide further assistance.
Sincerely,
Nikila
Thanks for the late reply..
Anyway that was not asked there. What i was asked, when there are that kind of formatting exists in the control, how to remove those things from the text. like if i don't want to save text with bold, when i press the save button in the code level i wanna remove the bold formatting from the text.
Hi Aruna,
I appologize, that I misunderstood your question.
WebHtmlEditor does not have an option to remove attributes from text, which are not defined by toolbar buttons. Actually that is not possible to implement, because WebHtmlEditor is not aware about browser's actions on most commands. For example, on "Bold" action, a browser may insert <strong> or <b> object.
WebHtmlEditor does automatic filtering of pasted content to replace attributes of Word by more standard html attributes, but that is different from your request.
WebHtmlEditor has property TextPlain, but, that will remove not only all attributes, but all other objects (like images, tables, etc.) as well.
In order to keep some attributes/objects and remove others, appication should use custom filtering with replacements and regular expressions.Simplest example to remove bold and italic tags.
string valueToSave = this.WebHtmlEditor1.Text;valueToSave = valueToSave.Replace("<strong>", "").Replace("</strong>", "").Replace("<b>", "").Replace("</b>", "").Replace("<i>", "").Replace("</i>", "").Replace("<em>", "").Replace("</em>", "");
Hi,
Thanks, Yes that was the way i handled it. I was thinking about a proper way of doing it using WebHtmlEditor properties.. Again thanks for the feedback.
Regards.