cannot access container data in templated control

  • Thread starter Achim Domma (SyynX Solutions GmbH)
  • Start date
A

Achim Domma (SyynX Solutions GmbH)

Hi,

I have implemented a templated control like described in the MSDN and
the Quick Start tutorial. In my aspx page, the control is used like this:

<syynx:SelectTableControl id="test" runat="server">
<Item>blabla <%# Container.Pos %><br></Item>
</syynx:SelectTableControl>

Below you can see the implementation of the templated control and the
container item. If the page is displayed, I only get five times 'blabla
<br>', so the property Pos seems to be ignored.

If I rename Pos to an invalid name I get an error. If I set a breakpoint
into the get method of Pos, I can see that the property is never accessed!?

Am I missing something? Any hint would be very appreciated!

regards,
Achim





[ParseChildren(true)]
public class SelectTableControl : Control, INamingContainer
{
private ITemplate item_;

[PersistenceMode(PersistenceMode.InnerProperty),TemplateContainer(typeof(ItemContainer))]

public ITemplate Item {
get { return item_; }
set { item_ = value; }
}

private Control itemContainer;

public override void DataBind()
{
EnsureChildControls();
base.DataBind();
}

protected override void CreateChildControls ()
{
if (Item != null)
{
for (int i=0 ; i < 5 ; ++i)
{
itemContainer = new ItemContainer(this,i);
Item.InstantiateIn(itemContainer);
Controls.Add(itemContainer);
}
}
else
{
Controls.Add(new LiteralControl("no template given"));
}
}
}

public class ItemContainer : Control, INamingContainer {
private int pos_;

public string Pos
{
get { return pos_.ToString(); }
set { pos_ = int.Parse(value); }
}

public ItemContainer(Control parent, int pos)
{
pos_ = pos;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top