More in this section

Forums / Developing with Sitefinity / Persisting Object State

Persisting Object State

9 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    15 Dec 2008
    Link to this post
    I want to enable in-page editing using the RadEditor control...so I've got two buttons which show/hide it and when hidden it just displays the html Content of the control...

    However when I return to the page, the content I entered is gone...how can I get the control to save?
  2. valio b
    valio b avatar
    33 posts
    Registered:
    24 Sep 2012
    16 Dec 2008
    Link to this post
    Hi Steve,

    We discussed this inquiry and apparently this feature is not available.
    Please consider implementing your own persistence logic. You may find the below resources useful in achieving your goals:
    http://www.telerik.com/help/aspnet-ajax/editor_getingreferencetoradeditor.html
    http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bgedkd.aspx

    I hope this helps.

    Regards,
    valio b
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    16 Dec 2008
    Link to this post
    Hmmm, okay, well I guess I can store it back into the database...can you tell me how to get the ControlID?
  4. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    01 Jun 2017
    16 Dec 2008
    Link to this post
    Hello Steve,

    You can try finding the ID with this javascript code:
    var editor = $find("<%=contentEditor.ClientID%>"); 
    where contentEditor is the server side ID of the Editor.

    Best wishes,
    Nikolay
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    16 Dec 2008
    Link to this post
    What about on the serverside?  I notice you're storing the controls by GUID in the database...if I can get the GUID I can tack extra properties to it myself
  6. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    16 Dec 2008
    Link to this post
    Ok, I made a stored proc to update the values...and it works
    (hardcoded GUID)

    However, it's updating the previous version of the control so it then works fine on rollback...how do I get the current edited guid version?
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 Dec 2008
    Link to this post
    Hi Steve,

    Could you explain us which control you are trying to edit and is it possible to send us some code of this implementation. It depends on which control you want to edit and how you want to do this. Also, we suggest working with the API.

    I noticed that you have managed to get this sorted out in this forum thread http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bmaedh.aspx
    Let us know if you need assistance.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    17 Dec 2008
    Link to this post
    I want to use the RadEditor to change Page content, so this shows\hides edit buttons based on role and saves content out to files as a workaround

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Telerik.Web.UI;
    using Telerik.DataAccess.AspnetProviders;
    using Telerik.Security;
    using System.Diagnostics;
    using System.ComponentModel;
    using System.IO;

    public partial class RichTextBoxInput : System.Web.UI.UserControl
    {
        private string _role;
        private string _cssStyle;
        private string _oldContent;
        private string _contentFile;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.Content))
                mainPanel.Controls.Add(new LiteralControl("No Text to Display"));
            else
            {
                this.AddContentToPage();
            }

            if (UserManager.GetCurrentUser().IsInRole(RoleManager.EditRole))
            {
                editControls.Visible = true;
            }

            mainPanel.CssClass = _cssStyle;
        }

        private void AddContentToPage()
        {
            mainPanel.Controls.Clear();
    //        this.Content = RadEditor1.Content;
            mainPanel.Controls.Add(new LiteralControl(this.Content));
        }

        public RadEditor Settings
        {
            get
            {
                return RadEditor1;
            }
        }

        protected void edit_Click(object sender, EventArgs e)
        {
            this.ShowControls = true;
            RadEditor1.Content = this.Content;
        }

        protected void save_Click(object sender, EventArgs e)
        {
            this.ShowControls = false;
            this.Content = RadEditor1.Content;
            this.AddContentToPage();
        }

        protected void cancel_Click(object sender, EventArgs e)
        {
            this.ShowControls = false;
            this.AddContentToPage();
        }

        private bool ShowControls
        {
            set
            {
                if (value == false)
                {
                    RadEditor1.Visible = false;
                    mainPanel.Visible = true;
                    editButton.Visible = true;
                    saveButton.Visible = false;
                    cancelButton.Visible = false;
                }
                else
                {
                    RadEditor1.Height = mainPanel.Height;
                    RadEditor1.Visible = true;
                    editButton.Visible = false;
                    saveButton.Visible = true;
                    cancelButton.Visible = true;
                    mainPanel.Visible = false;
                }
            }
        }

        public string ContentFile
        {
            get
            {
                return _contentFile;
            }
            set
            {
                _contentFile = value;

                if(_contentFile!=null)
                    this.CreateFile(Path + _contentFile);
            }
        }

        public string Content
        {
            get
            {
                string content = String.Empty;

                if(_contentFile != null)
                {
                    StreamReader reader = new StreamReader(Path  + _contentFile);

                    while (!reader.EndOfStream)
                        content += reader.ReadLine();

                    reader.Close();
                    //RadEditor1.Content = content;
                }
                return content;
            }
            set
            {
                if (!String.IsNullOrEmpty(_contentFile))
                {
                    StreamWriter writer = new StreamWriter(Path + _contentFile);

                    writer.Write(value);

                    writer.Close();
                }
            }
        }

        private void CreateFile(string path)
        {
            if (!File.Exists(path))
            {
                FileStream newfile = new FileStream(path, FileMode.Create);
                newfile.Close();
            }
        }

        public string AllowEditsFromRole
        {
            get
            {
                return _role;
            }
            set
            {
                _role = value;
            }
        }

        private string Path
        {
            get
            {
                return Server.MapPath(@"~\App_Data\ControlContent\");
            }
        }

        public string CssStyle
        {
            get
            {
                return _cssStyle;
            }
            set
            {
                _cssStyle = value;
            }
        }
    }

  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 Dec 2008
    Link to this post
    Hi Steve,

    Take a look at this forum thread where I posted a way to get a control GUID.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
9 posts, 0 answered