Rendering user controls in EPIserver dynamic content

2.1k views Asked by At

Im trying to make a EPIserver dynamic content control, the content i want is a user control which i already made(a slider), every thing seems to work just fine until i insert the dynamic content control onto the page/area i want to use it.

When i now go to the page i have created it displays the "static" content:

<h3>Dynamic slider</h3>
<TextBox runat="server" ID="txtTest" />
<cd:TopSlider runat="server" ID="MySlider"/>

out of these 3 items the header and the textbox is shown, but not the "cd:TopSlider", and in the OnPageLoad i set the text in the TextBox to 'FooBar' but this is not displayed either, it seams it never goes server-side, I've tried to place breakpoints but non is triggered . . .

Here is the code for the DynamicContent files:

The usercontrol which is loaded DynamicContentTest.ascx.cs:

public partial class DynamicContentTest : System.Web.UI.UserControl
    {
        public IEnumerable<SliderPage> DataSource { get; set; }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            txtTest.Text = "FooBar";

            MySlider.DataSource = DataSource;
            MySlider.DataBind();

        }
    }

DynamicContentTest.ascx:

<%@ Register TagPrefix="cd" TagName="TopSlider" Src="~/UserControls/TopSlider.ascx" %>
<!-- Slider -->
<h3>Dynamic slider</h3>
<asp:TextBox runat="server" ID="txtTest" />
<cd:TopSlider runat="server" ID="mySlider"/>
<!-- END Slider -->

DynamicContentControl:

[DynamicContentPlugIn(
        DisplayName = "Dynamic slider",
        Description = "Displays a slider",
        ViewUrl = "~/UserControls/DynamicContent/Custom/DynamicContentTest.ascx")]
    public class DynamicSliderControl : UserControlBase
    {
        public PageReference SlidesRoot { get; set; }

        public System.Web.UI.Control GetControl(EPiServer.PageBase hostPage)
        {
            var userControl = (UserControls.DynamicContent.Custom.DynamicContentTest)hostPage.LoadControl("~/UserControls/DynamicContent/Custom/DynamicContentTest.ascx");
            userControl.DataSource = SlidesRoot != null ?
                SlidesRoot.GetChildrenOfType<SliderPage>() : null;
            return userControl;
        }

        public bool RendersWithControl
        {
            get { return true; }
        }

        public string State { get; set; }
    }

I used these articles as guide's:

Create EPiServer dynamic content with advanced settings

Creating simple Dynamic Content in EPiServer CMS 6 R2

2

There are 2 answers

2
tompipe On BEST ANSWER

Are you using an EPiServer:Property control to render the dynamic content?

If you don't use this, EPiServer doesn't have chance to intercept the Dynamic Content and render it out appropriately.

0
tompipe On

We use pagetype builder so we would still like to work around EPiServer:property

In that case, this link may help you.