S
Sky Sigal
Hello:
Going nuts looking for someone who can solve this riddle...
ControlBuilder -- according to what I've seen -- parses attributes of
declarative tags in alphabetic order, then parses nested tags in alphabetic
order.
And that is causing me a lot of trouble...
Take for example the following control:
<myControl>
<Items>
<ListItem>Uno</ListItem>
<ListItem>Dos</ListItem>
</Items>
<Templates>
<Main>
...insert here layout containinng one DropDownList that
...will be destination of above mentioned ListItems
</Main>
</Templates>
</MyControl>
In other words, the parser will process Items first, and if we follow
Nikhil's suggested pattern of calling EnsureChildControls first, we will get
an exception -- because TemplateMain is still null.
If we provide a DefaultTemplate to fix this, we then end up with Items being
processed, EnsureChildControls making a layout with the default template
built into the control, then the parser parses Templates/Main, and resets
ChildControlsCreated=false. ...So PreRender calls EnsureChildControls, which
rebuilds the whole control with the new provided template...
And the final mess is that we have the right template, but the drop down is
empty because we threw away the original list of items.
Yikes.
Switch to Deffered Delegation, and make a IStateManaged ListItemCollection
in the Container
get {
if (_Items==null){_Items = new ListItemCollection();
if (this.TrackingViewState){((IStatemanager)_Items).TrackViewState();}
return _Items;
}
and apply it later we have two choices -- that don't work.
If we apply it in PrepareControlHierarchy, it's great...until
postback...when we will always have a SelectedIndex of -1, because for the
whole life of the control up to Render the inner listControl's list contains
exactly 0 elements (they are still in the container's Items collection)...
If we apply them in CreateChildControls, before adding the templatecontainer
to the control, we end up with an Items property that is out of date...before
CreateChildControls (CCC) it is the right list, but after CCC, the Items of
importance are the innerList.Items... which we are not pointed at.
So questions are:
a) If Immediate delegation is used, how can ControlBuilder be taught in
which order to process attributes? So that it sets up Template before it
works on Items?
b) If Delayed delegation used, how to set it up so that SelectedIndex is a
property that works?
c) If Delayed delegation -- how can it work with a nested gridview (ie no
IStatemanager object to persist data in, so has to be handled in
CreateChildControls as far as I can tell).
Thanks very much,
Sky
Going nuts looking for someone who can solve this riddle...
ControlBuilder -- according to what I've seen -- parses attributes of
declarative tags in alphabetic order, then parses nested tags in alphabetic
order.
And that is causing me a lot of trouble...
Take for example the following control:
<myControl>
<Items>
<ListItem>Uno</ListItem>
<ListItem>Dos</ListItem>
</Items>
<Templates>
<Main>
...insert here layout containinng one DropDownList that
...will be destination of above mentioned ListItems
</Main>
</Templates>
</MyControl>
In other words, the parser will process Items first, and if we follow
Nikhil's suggested pattern of calling EnsureChildControls first, we will get
an exception -- because TemplateMain is still null.
If we provide a DefaultTemplate to fix this, we then end up with Items being
processed, EnsureChildControls making a layout with the default template
built into the control, then the parser parses Templates/Main, and resets
ChildControlsCreated=false. ...So PreRender calls EnsureChildControls, which
rebuilds the whole control with the new provided template...
And the final mess is that we have the right template, but the drop down is
empty because we threw away the original list of items.
Yikes.
Switch to Deffered Delegation, and make a IStateManaged ListItemCollection
in the Container
get {
if (_Items==null){_Items = new ListItemCollection();
if (this.TrackingViewState){((IStatemanager)_Items).TrackViewState();}
return _Items;
}
and apply it later we have two choices -- that don't work.
If we apply it in PrepareControlHierarchy, it's great...until
postback...when we will always have a SelectedIndex of -1, because for the
whole life of the control up to Render the inner listControl's list contains
exactly 0 elements (they are still in the container's Items collection)...
If we apply them in CreateChildControls, before adding the templatecontainer
to the control, we end up with an Items property that is out of date...before
CreateChildControls (CCC) it is the right list, but after CCC, the Items of
importance are the innerList.Items... which we are not pointed at.
So questions are:
a) If Immediate delegation is used, how can ControlBuilder be taught in
which order to process attributes? So that it sets up Template before it
works on Items?
b) If Delayed delegation used, how to set it up so that SelectedIndex is a
property that works?
c) If Delayed delegation -- how can it work with a nested gridview (ie no
IStatemanager object to persist data in, so has to be handled in
CreateChildControls as far as I can tell).
Thanks very much,
Sky