ASPX templates
Version 6.x > ASPX templates > CMSRepeater in UserControls View modes: 
User avatar
Member
Member
robert-tailor.co - 10/9/2012 8:18:13 PM
   
CMSRepeater in UserControls
Hi,

I've got a UserControl that contains a CMSRepeater control:

<cms:CMSRepeater ID="CMSRepeaterShapes" runat="server" ClassNames="My.Document">
<ItemTemplate><%# RenderShapeLink(Eval("DocumentName").ToString(), Eval("NodeAliasPath").ToString()) %></a></ItemTemplate>
<SeparatorTemplate> / </SeparatorTemplate>
</cms:CMSRepeater>


RenderShapeLink() is a function in the UserControl code behind.

My UserControl is included on a TemplatePage and relies on a Property being assigned to it in the TemplatePage's Page_Init().

Amazingly, CMSRepeater evaluates before Page_Init() has been fired. This causes the RenderShapeLink() method to run before the critical value in the UserControl has been set.

Even worse, I cannot set the UserControl's required Property in Page_PreInit() because the control has not been created in memory by that stage.

I'm having to use a standard Repeater now instead, and set everything manually.

What's going on here? Why does CMSRepeater evaluate so early in the ASP.NET page lifecycle?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/9/2012 10:54:37 PM
   
RE:CMSRepeater in UserControls
Hi,

The life cycle in Kentico is little bit different than in standard ASP.Net - due to the portal engine and mixed modes.

You need to load your user control dynamically or, if using portal engine, you can use the "User control" web part and specify the path to your user control in its configuration and this web part is loading the user control dynamically and ensures the "correct" life cycle in Kentico.

Best regards,
Juraj Ondrus