Can we use Inline Editing on Custom Controls

Posted by Community Admin on 05-Aug-2018 16:22

Can we use Inline Editing on Custom Controls

All Replies

Posted by Community Admin on 22-Mar-2011 00:00

I would like to set up a user control that supports front end editing.  The ideal scenario would allow me to use the custom designer I have already set up for this control. Is there an established way to achieve this?  If so, can someone provide me a resource link or some direction to get me started.

Thanks
Posted by Community Admin on 22-Mar-2011 00:00
Hi Drew,

It is possiblem but your control should implement IBrowseAndEditable interface.

Kind regards,
Ivan Dimitrov
the Telerik team
Posted by Community Admin on 22-Mar-2011 00:00
Thanks Ivan,
I think I've implemented the interface correctly, but I'm getting an exception thrown from a telerik class.

The method that's failing isBrowseAndEdit.PropertyEditorBrowseAndEditStrategy.Configure here is the stack trace.
[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit.PropertyEditorBrowseAndEditStrategy.Configure(Object instance, Guid pageId) +592
   Telerik.Sitefinity.Modules.Pages.StaticPageData.CreateChildControls(Page page, Boolean isFrontEndPage) +807
   Telerik.Sitefinity.Web.PageRouteHandler.ApplyLayoutsAndControls(Page page, RequestContext requestContext) +212
   Telerik.Sitefinity.Web.RouteHandler.InitializeContent(Page handler, RequestContext requestContext) +276
   Telerik.Sitefinity.Web.RouteHandler.Handler_Load(Object sender, EventArgs e) +215
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

I'm going to add some code here for the example control as well. Everything but the designer anyway.
UserControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UserControl.ascx.cs" Inherits="SitefinityWebApp.controls.UserControl" %>
<%@ Register TagPrefix="sf" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" %>
<sf:BrowseAndEditToolbar ID="browseAndEditToolbar" runat="server" Mode="Edit"></sf:BrowseAndEditToolbar>
<div class="example">
<ul>
<li><asp:Literal ID="Prop1" runat="server" Text="Property 1"></asp:Literal></li>
<li><asp:Literal ID="Prop2" runat="server" Text="Property 2"></asp:Literal></li>
<li><asp:Literal ID="Prop3" runat="server" Text="Property 3"></asp:Literal></li>
<li><asp:Literal ID="Prop4" runat="server" Text="Property 4"></asp:Literal></li>
</ul>
</div>

Here is UserControl.ascx.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Telerik.Sitefinity.Web.UI.ControlDesign;
using Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit;
 
namespace SitefinityWebApp.controls
    [ControlDesigner(typeof(UserControlDesigner))]
    public partial class UserControl : System.Web.UI.UserControl, IBrowseAndEditable
    
        public UserControl()
                this.commands = new List<BrowseAndEditCommand>();
        
 
        [Category("A Category Name")]
        public virtual string Property1 get; set;
        [Category("A Category Name")]
        public virtual string Property2 get; set;
        [Category("A Category Name")]
        public virtual string Property3 get; set;
        [Category("A Category Name")]
        public string Property4 get; set;
         
        #region IBrowseAndEditable Members
        // Fields
         private List<BrowseAndEditCommand> commands = new List<BrowseAndEditCommand>();
        // Methods
        public void AddCommands(IList<BrowseAndEditCommand> cmds)
            this.commands.AddRange(cmds);
        
        BrowseAndEditToolbar IBrowseAndEditable.BrowseAndEditToolbar
            get return this.browseAndEditToolbar;
        
        #endregion
         
        protected void Page_Load(object sender, EventArgs e)
            this.browseAndEditToolbar.Commands.AddRange(this.commands);
            BrowseAndEditManager current = BrowseAndEditManager.GetCurrent(this.Page);
            if (current != null)
                current.Add(this.browseAndEditToolbar);
 
            Prop1.Text = string.IsNullOrWhiteSpace(Property1) ? "EMPTY1" : Property1;
            Prop2.Text = string.IsNullOrWhiteSpace(Property2) ? "EMPTY2" : Property2;
            Prop3.Text = string.IsNullOrWhiteSpace(Property3) ? "EMPTY3" : Property3;
            Prop4.Text = string.IsNullOrWhiteSpace(Property4) ? "EMPTY4" : Property4;
        
    

Thanks for the response and thanks for any additional help you can provide,
Drew
Posted by Community Admin on 28-Mar-2011 00:00
Hi Drew,

Currently InLine editting can be extended only with custom controls, please convert your control to custom control and instead of page load use initializecontrols.

Greetings,
Pavel
the Telerik team
Posted by Community Admin on 18-Oct-2011 00:00
Pavel,

Is this still the case, where the BrowseAndEdit functionality can only be used with Custom Controls or can it be used with User Controls now?

Many thanks,
Andrei
Posted by Community Admin on 21-Oct-2011 00:00
Hi Andrei,

Yes, it is possible. Please check the blog post here:
http://www.sitefinity.com/blogs/stanislavvelikov/posts.aspx

Best wishes,
Pavel Iliev
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
This thread is closed