Persisting Custom Colors?

3 posts, 1 answers
  1. Mark Kucera
    Mark Kucera avatar
    84 posts
    Member since:
    Sep 2009

    Posted 19 May 2010 Link to this post

    I'm using the RadControls v2010.1.309.35


    With the rad editor is there a way to persist custom colors so that when a user comes back their custom colors are retained?  i'm fine with using a cookie approach if necessary so that the custom colors are user/browser specific.

    Thanks!
    -Mark

  2. Answer
    Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 20 May 2010 Link to this post

    Hi Mark,

    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. As a workaround I suggest you to pass the client-side color collection on the server upon postback using an Hidden Field, e.g.:
    Copy Code
    <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.:
    Copy Code
    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]);
            }
        }
    }


    Once you receive the custom colors you can save them in a database and load them depending on the logged user.

    Greetings,
    Rumen
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mark Kucera
    Mark Kucera avatar
    84 posts
    Member since:
    Sep 2009

    Posted 20 May 2010 Link to this post

    Thanks Rumen, for the most part i was able to take this as is and make it work.    I set it up using cookies as the storage method which will work for our scenario.  We have lots of controls and postbacks on this page so figuring out where to insert the save/update/load code to some work but otherwise i think this will work just fine.  I appreciate the quick reply.

    -Mark
Back to Top