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;
}
}
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;
}
}