Image selector on custom widget edit designer
I've been having lots of problems getting this to work.
I have a custom user control that has been implemented into Sitefinity as a custom widget. This is called MainTabs.ascx. I am trying to customize the edit designer window that users will see so when they click "Edit" on the widget, they will see a text field and an image selector.
I have used some code found here and the project builds fine. However, when I go to view my page in Edit mode within Sitefinity, I get the following error: "'SitefinityWebApp.UserControls.MainTabs' is not allowed here because it does not extend class 'System.Web.UI.UserControl'.
"
I understand what this means. If I'm extending the SimpleView in my user control code behind, then I cannot inherit UserControl. But if I don't inherit UserControl, then it won't display.
So, how can I make a custom widget user control editable using the SimpleView?
Here is my current code: MainTabs.ascx.cs
using System;using System.Collections.Generic;using System.ComponentModel;using System.Linq;using System.Text;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Sitefinity.Web.UI;using Telerik.Sitefinity.Web.UI.ControlDesign;using Telerik.Sitefinity.Modules.Pages.Web.UI;using Telerik.Sitefinity.Modules.Libraries.Images;using Telerik.Sitefinity;namespace SitefinityWebApp.UserControls [ControlDesigner(typeof(SitefinityWebApp.UserControls.Designers.MainTabsDesigner))] public partial class MainTabs : SimpleView protected Image mainImageLeft get return Container.GetControl<Image>("mainImageLeft", true); protected override void InitializeControls(GenericContainer container) if (ImageId.ToString().Length > 1) Telerik.Sitefinity.Libraries.Model.Image image = App.WorkWith().Image(ImageId).Get(); mainImageLeft.ImageUrl = image.MediaUrl; protected override string LayoutTemplateName get return "SitefinityWebApp.UserControls.MainTabs.ascx"; private Guid _imageId; public Guid ImageId get return this._imageId; set this._imageId = value; Hello Brad H,
Your control shouldn't have an ascx.cs file, but just an .ascx file which is the template of the control and a .cs file which is the control's main class. The code you have provided is correct, the only thing you need to do is change the directive of your .ascx file to just:
<%@ Control Language="C#" %>Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
Hello Brad H,
Path to the template LayoutTemplateName should be a template file, that is .ascx only. Which means your MainTabs class should be just a .cs (without any designer.cs and .ascx). Designers and templates loosely coupled!
Please see this documentation.