Programmatically color-highlighting the text contained in the editor

Last post 04-14-2010, 12:18 AM by Kenneth. 2 replies.
Sort Posts: Previous Next
  •  04-13-2010, 11:11 AM 60061

    Programmatically color-highlighting the text contained in the editor

    Hello, I was wondering if anyone knew what the approach would be to programmatically highlight text in the editor in asp.net.  By "highlighting" the text, I mean the equivalent of text highlights in Microsoft Word or the use of background-color in html lingo (they both look the same).  For example, let's say my editor contains this statement...
     
    All work and no play makes Jack a dull boy.
     
    And I want it to look like this...
     
    All work and no play makes Jack a dull boy.
     
    How would I go about doing this programmatically in asp.net?  Obviously, the color and the location (indexes within the string) are variables I need to feed into the code.  The highlights would turn on/off with the firing of an event (say toggling a radio button or a checkbox that is outside the editor).
     
    Thank you in advance.

    ~Paul
  •  04-13-2010, 3:32 PM 60069 in reply to 60061

    Re: Programmatically color-highlighting the text contained in the editor

    I assume nobody has a clue?
     
    As of now, I'm just getting the value of Editor1.Text, doing an htmlencode on it and appending the <font style etc etc etc> myself to make a new string.  Then I just re-set Editor1.Text to that new updated string.  This is of course sticking the whole editor inside an AJAX updatepanel.  The highlighting of the text occurs in the vb codebehind aka it makes a trip to the server.  Then, when the event is fired to de-highlight some text, I just manually remove that <font style> tag around that target word and re-set the new string into the editor.
     
    I don't know if the aforementioned is the "ghetto" and unsophisticated way of doing this, which is why I asked if there was a more logical and better way to implement this. 

    ~Paul
  •  04-14-2010, 12:18 AM 60080 in reply to 60069

    Re: Programmatically color-highlighting the text contained in the editor

    s2kdriver80:
    I assume nobody has a clue?
     
    As of now, I'm just getting the value of Editor1.Text, doing an htmlencode on it and appending the <font style etc etc etc> myself to make a new string.  Then I just re-set Editor1.Text to that new updated string.  This is of course sticking the whole editor inside an AJAX updatepanel.  The highlighting of the text occurs in the vb codebehind aka it makes a trip to the server.  Then, when the event is fired to de-highlight some text, I just manually remove that <font style> tag around that target word and re-set the new string into the editor.
     
    I don't know if the aforementioned is the "ghetto" and unsophisticated way of doing this, which is why I asked if there was a more logical and better way to implement this. 
     
    Hi s2kdriver80,
     
    Try the example below
     
    1. <%@ Page Language="C#" Debug="true" %>   
    2.   
    3. <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>   
    4. <html>   
    5. <head>   
    6. </head>   
    7.   
    8. <body>   
    9.     <form id="Form1" runat="server">   
    10.         <CE:Editor ID="Editor1" runat="server">   
    11.         </CE:Editor>   
    12.                <input type="button" value="Adding color to text" onclick="addColor()" />   
    13.     </form>   
    14. </body>   
    15. </html>   
    16.   
    17. <script>   
    18. function addColor()   
    19.  {    
    20.     var editor1 = document.getElementById('<%=Editor1.ClientID%>');   
    21.     editor1.ExecCommand("ForeColor",false,"blue");   
    22.                 
    23. }   
    24. </script>  
    Regards,
     
    Ken
View as RSS news feed in XML