在 EPIserver 动态内容中呈现用户控件

发布于 2024-12-25 10:00:49 字数 2532 浏览 1 评论 0原文

我正在尝试制作 EPIserver 动态内容控件,我想要的内容是我已经制作的用户控件(滑块),一切似乎都工作正常,直到我将动态内容控件插入我想要使用的页面/区域它。

当我现在转到我创建的页面时,它显示“静态”内容:

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

在这 3 个项目中,显示标题和文本框,但不显示“cd:TopSlider”, 在 OnPageLoad 中,我将 TextBox 中的文本设置为“FooBar”,但这也没有显示,它接缝它永远不会进入服务器端,我尝试放置断点,但没有触发。 。 。

以下是 DynamicContent 文件的代码:

加载的用户控件 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; }
    }

我使用了这些作为指南的文章:

使用高级设置创建 EPiServer 动态内容

在 EPiServer CMS 6 R2 中创建简单的动态内容

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趁年轻赶紧闹 2025-01-01 10:00:50

我们使用页面类型构建器,因此我们仍然希望解决 EPiServer:property

在这种情况下, 链接可能对您有帮助。

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

In that case, this link may help you.

萌化 2025-01-01 10:00:49

您是否使用 EPiServer:Property 控件来呈现动态内容?

如果您不使用此功能,EPiServer 将没有机会拦截动态内容并将其正确呈现。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文