More in this section

Forums / Developing with Sitefinity / Save Property Value on Public Side

Save Property Value on Public Side

5 posts, 0 answered
  1. Eric Wallace
    Eric Wallace avatar
    66 posts
    Registered:
    08 Oct 2009
    10 May 2010
    Link to this post
    I have a custom user control in which the user is allowed to modify a property value, and that value needs to be saved just as if it was modified in the Sitefinity admin section. How would I go about doing this?

    Thanks,
    Eric
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    10 May 2010
    Link to this post
    Hello Eric Wallace,

    You could use ProfileBase.SetPropertyValue Method

    All the best,
    Ivan Dimitrov
    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. Eric Wallace
    Eric Wallace avatar
    66 posts
    Registered:
    08 Oct 2009
    10 May 2010
    Link to this post
    Hi Ivan, I apologize for not being more clear. I have a user control that has been added to the toolbox collection for use on any page. On that control, there is a public property called Biography that can be set when editing the page by an admin, but it can also be modified by a person if he/she is the owner of that biography on the public side by clicking an edit icon and modifying the value of the Biography property via a RadEditor embedded in the user control, then clicking an "I'm Done" button. On the event handler for the I'm Done button, I need to save the content of the RadEditor as the Value for the Biography property.

    EmployeeProfile.ascx
    <div id="biography">
      <h2>Biography <asp:HyperLink id="edit" runat="server" navigateurl="javascript:void(null)" onclick="EditBio();" imageurl="~/images/icons/editUser.gif" title="Edit your biography" text="Edit your biography" Visible="False" /></h2>
      <div id="body"><asp:Literal id="biography" runat="server" /></div>
      <div id="edit">   
        <telerik:RadEditor ID="reEditBio" runat="server" toolsfile="~/Sitefinity/Admin/ControlTemplates/EditorToolsFile.xml" ContentAreaCssFile="~/css/RadEditor.css" Width="794px" />
        <br />
        <asp:LinkButton id="lBtnDone" runat="server" onclick="lBtnDone_Click" cssclass="CmsButLeft ok"><strong class="CmsButRight light">I'm done</strong></asp:LinkButton>
      </div
    </div>


    EmployeeProfile.ascx.cs
    [WebEditor("MyCompany.Web.UI.RadEditorSelector, App_Code")]
        public string Biography
        {
            get
            {
                return (string)ViewState["Employee_Biography"];
            }
            set
            {
                ViewState["Employee_Biography"] = value;
            }
        }
     
        protected void lBtnDone_Click(object sender, EventArgs e)
        {
                this.Biography = reEditBio.Content;
                // implement CMS save logic here.
        }

    So basically I need to implement the logic to save the Biography property value for the control on the current page the same way it is saved on the CMS admin side when editing the control property.

    Thanks,
    Eric
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 May 2010
    Link to this post
    Hi Eric Wallace,

    In the page lifetime cycle view state is available between the Init  and PreRender events. There are two ways that I could suggest.

    1. Get the current page and your control on it. Then set the property.

    sample code

    page = (ICmsPage)Manager.GetPage(page.ID, true);
    staged = page.Staged.CheckOut();
    foreach (ICmsWebControl cntrl in staged.Controls)
    {
        if (cntrl.IsAscx && cntrl.TypeName == "~/UserControls/BiographyControl.ascx")
        {
            Control c = cntrl.LoadControl(this.Page);
            UserControls_BiographyControl mycontrol = c as UserControls_BiographyControl;
      
            mycontrol.Biography= "some value here";
            Manager.SaveControl(cntrl);
            ((ICmsPage)Manager.GetPage(page.ID, true)).Staged.CheckIn();
            Nolics.ORMapper.Base.DataConnection.InitWebRequest();
            break;
      
        }
    }

    2. Create a custom database table to persist the property value.

    Kind regards,
    Ivan Dimitrov
    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.
  5. Eric Wallace
    Eric Wallace avatar
    66 posts
    Registered:
    08 Oct 2009
    11 May 2010
    Link to this post
    It's partially working now. What's strange is that it only saves every other time the event handler is run, regardless of whether or not it is a postback.

    protected void lBtnDone_Click(object sender, EventArgs e)
        {
            ICmsUrlContext pageKey = (ICmsUrlContext)this.Context.Items[Telerik.Cms.Web.UrlHelper.CmsPageKey];
            CmsManager mgr = new CmsManager();
            ICmsPage page = (ICmsPage)mgr.GetPage(pageKey.PageID, true);
            IStagedPage staged = page.Staged.CheckOut();
     
            foreach (ICmsWebControl ctrl in staged.Controls)
            {
                if (ctrl.IsAscx && ctrl.TypeName == "~/UserControls/EmployeeProfile.ascx")
                {
                    Control c = ctrl.LoadControl(this.Page);
                    UserControls_EmployeeProfile profile = c as UserControls_EmployeeProfile;
                    profile.Biography = reEditBio.Content;
                    mgr.SaveControl(ctrl);
                    ((ICmsPage)mgr.GetPage(pageKey.PageID, true)).Staged.CheckIn();
                    profile.Dispose();
                    break;
                }
            }
     
            this.biography.Text = reEditBio.Content;
        }
Register for webinar
5 posts, 0 answered