Change background color in editor

5 posts, 1 answers
  1. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 10 Dec 2008 Link to this post

    I know this can be done but I don't know how! :)

    I have an radEditor and a radColorPicker.
    Now, I want to change the editors background color when selecting a color, how do I do that?

    /Mattias
  2. Answer
    Rumen
    Admin
    Rumen avatar
    12847 posts

    Posted 10 Dec 2008 Link to this post

    Hi Mattias,

    This one should be easy. You need to attach to the OnClientColorChange or OnClientColorSelecting event of RadColorPicker and obtain the selected color. After that set it as a value to the editor.get_contentArea().style.backgroundColor = "color value returned by RadColorPicker".

    Best regards,
    Rumen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 10 Dec 2008 Link to this post

    Got it! :)

    <telerik:RadColorPicker ID="radColorPickerBackgroundColor" runat="server"  
                                        Preset="Default" OnClientColorChange="HandleClientValueChange"
                                    </telerik:RadColorPicker> 
                                
                                    <telerik:RadEditor ID="radEditorText" Runat="server" Height="334px" Width="221px"
                                       <CssFiles> 
                                            <telerik:EditorCssFile Value="/Style/PublicStyle.css" /> 
                                        </CssFiles> 
                                           </telerik:EditorToolGroup> 
                                    </telerik:RadEditor> 
    <script type="text/javascript"
                            function HandleClientValueChange(sender, eventArgs) { 
                                var editor = $find("<%=radEditorText.ClientID%>"); 
                                var style = editor.get_contentArea().style; 
                                style.backgroundColor = sender.get_selectedColor(); 
                            } 
                        </script> 

  5. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 11 Dec 2008 Link to this post

    Hmm, how can I set it code behind?
    Have tried with:
    radEditorText.Style.Add(HtmlTextWriterStyle.BackgroundColor, CurrentBanner.BackgroundColor);
    and
    radEditorText.BackColor = ColorTranslator.FromHtml(CurrentBanner.BackgroundColor);
    but it seems to have no effect!




  6. Rumen
    Admin
    Rumen avatar
    12847 posts

    Posted 11 Dec 2008 Link to this post

    Hi Mattias,

    Currently, you can use only the client-side solution, because the server BackColor property is inherited from the base control of RadEditor and it is not yet implemented. If you want to have a server-side solution, you could import the javascript code from the codebehind using the ScriptManager.RegisterClientScriptBlock() server method.

    Best regards,
    Rumen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017