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

Store custom colors per usergroup?

1 Answer 28 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Ruud van der Veer
Top achievements
Rank 1
Ruud van der Veer asked on 03 Aug 2010, 03:26 PM
In the newer versions the add custom color functions was reintroduced for cell and table background colors. Is it possible to store the added colors per usergroup for later usage?

1 Answer, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 05 Aug 2010, 11:31 AM
Hi Ruud,

You can use RadEditor's client side methods get_colors() and set_colors() in order to preserve the previously added colors. For example you can assign a handler to the onBeforeUnload window event to store current color collection in a cookie and then use that cookie to set this collection to the editor OnClientLoad event.
  • get_colors() - this method returns an array of all the colors in ColorPicker palette
  • set_colors(colors) - this method requires an array property and set the color palette in the ColorPicker dropdown
In addition, RadEditor populates its color collection on the client (on the first loading of the ColorPicker dropdown) and it is not accessible on the server, so in order to preserve the custom colors that were added I suggest you to pass the client-side color collection on the server upon postback using an Hidden Field, e.g.:
<telerik:RadEditor ID="RadEditor1" runat="server">
</telerik:RadEditor>
  
<asp:Button ID="Button1" runat="server" Text="Button1" OnClientClick="beforePostbackHandler()" />
  
<input type="hidden" id="colorArray" runat="server" />
  
<script type="text/javascript">
    var beforePostbackHandler = function()
    {
        var editor = $find("<%= RadEditor1.ClientID %>");
        var colorArray = document.getElementById("colorArray");
  
        colorArray.value = editor.get_colors();
    }
</script>
and after that add these colors to the server-side collection on pageLoad, e.g.:
protected void Page_Load(object sender, EventArgs e)
{
    if (colorArray.Value != "")
    {
        string[] colors = colorArray.Value.Split(new char[]{','});
  
        for (int i = 0; i < colors.Length; i++)
        {
            RadEditor1.Colors.Add(colors[i]);
        }
    }
}

I hope this helps.

Greetings,
Dobromir
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Editor
Asked by
Ruud van der Veer
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Share this question
or