UserControl with Child Controls passed into a Repeater within the UserControl?

You've got the parse and persist the wrong way round.

Up vote 4 down vote favorite share g+ share fb share tw.

I'm trying to achieve something along the lines of... UserControl (MyRepeater) Control Start Control End Page Page Start Page Item Template Page End The ItemTemplate from the Page object will be used as the ItemTemplate of the Repeater within the UserControl. The reason for this is that we use a number of repeaters throughout our application, each repeater and some corresponding buttons perform some similar code. I would like to keep this code all in one place so that developers can use our custom Repeater control rather than having to create the code in every page every time it is needed.

I have done similar in the past with a WebControl by creating a Repeater control within the RenderContents method of my Repeater control and everything works as I would expect. The reason I would like to use a UserControl as there will be a number of Style/Layout type changes that may need to be made between systems, this will be much easier as a UserControl where the html/asp can be edited directly. Currently the code behind of my UserControl looks like this.

ParseChildren(false) PersistChildren(true) public partial class MyRepeater : System.Web.UI. UserControl, INamingContainer { protected void Page_Init(object sender, EventArgs e) { myRepeater. ItemTemplate = this.

ItemTemplate; } protected void Page_Load(object sender, EventArgs e) { //Temporary bind for testing myRepeater. DataSource = Enumerable. Range(1, 5); myRepeater.DataBind(); } DefaultValue("") Browsable(false) PersistenceMode(PersistenceMode.

InnerProperty) TemplateContainer(typeof(RepeaterItem)) public virtual ITemplate ItemTemplate { get; set; } } In short, it's just not working... The contents of the Page ItemTemplate are being rendered after the entire UserControl and not within the repeater. Can anyone indicate where I may be going wrong and/or point me in a better direction? C# asp.net usercontrols repeater link|improve this question asked Oct 16 '09 at 13:12Robin Day19.4k53579 77% accept rate.

Page_Init in the control will be run before the Page_Init of the Page - is myRepeater. ItemTemplate being set? – Graham Clark Oct 16 '09 at 13:34 It isn't, I've just found that exact issue.

This. ItemTemplate in the Page_Init is null. In fact, it seems to always be null.

I'm not sure where I can pick it out in order to use it as it won't have been rendered yet. – Robin Day Oct 16 '09 at 13:37.

You've got the parse and persist the wrong way round. You want ParseChildren(true) PersistChildren(false).

What a numpty... yes... that was exactly it. Thanks! – Robin Day Oct 16 '09 at 13:58.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions