在 EPIserver 动态内容中呈现用户控件
我正在尝试制作 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; }
}
我使用了这些作为指南的文章:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下, 此链接可能对您有帮助。
In that case, this link may help you.
您是否使用 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.