This is a migrated thread and some comments may be shown as answers.

Highlight specific word in Rad Editor

1 Answer 162 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
A
Top achievements
Rank 1
A asked on 04 Nov 2014, 05:08 AM
Hi ,

I didn't find any method in Radeditor control to Find a particular word and highlight it.Please throw me any suggestions how can i achieve this ?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 06 Nov 2014, 01:37 PM
Hi,

If you are looking for server-side method to do that, there is none that OOB will enable you to search and highlight a specific word.

Note that the RadEditor is an XHTML editor and has the ability to select DOM elements in the content area using the client-side selectElement() method.

For example:
<telerik:RadEditor ID="RadEditor1" runat="server">
    <Content>
        <p>some text</p>
        <p id="paragraphToSelect">paragraph to select</p>
        <p>some more text</p>
    </Content>
</telerik:RadEditor>
 
<telerik:RadButton runat="server" ID="RadButton1" AutoPostBack="false" OnClientClicked="OnClientClicked">
</telerik:RadButton>
 
<script type="text/javascript">
    function OnClientClicked(sender, args) {
        var $ = jQuery = $telerik.$; // This is needed if there is no jQuery referenced directly in the page.
        var editor = $find("<%= RadEditor1.ClientID %>");
        var contentBody = editor.get_contentArea();
        var elmToSelect = $(contentBody).find("#paragraphToSelect")[0];
 
        editor.selectElement(elmToSelect);
    }
</script>

Another approach is using the range objects, although creating a proper range is complex and the best approach is to firstly get one and reuse it if needed. You can refer to this help article about the Range.

Alternative approach is to use directly browser functionality to search in content area. This approach is the most complex one and to further examine it I recomend directly investigating how the Find and Replace dialog is created by getting the FindAndReplace.ascx file from the installation folder of the installed controls (C:\Program Files (x86)\Telerik\UI for ASP.NET AJAX QX YYYY\EditorDialogs).

Regards,
Ianko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
A
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Share this question
or