Immediate v. Delayed Delegation of Properties in CompositeControls

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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






.



Relevant Pages

  • RE: Id guess I cant do this
    ... Templated User Control. ... Creating the Template Class ... When you have a dynamic template available, you can instantiate it in code. ... Add a data-binding event handler to the controls you create in the template. ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Resolving datasource expression
    ... | a custom ASP.NET template databound control and the control will display ... | DataItem is just a propety of the "Container", ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Listing objects
    ... App will be the root, ... asks a Control to do that. ... a page has a template ... So, after Controller instantiates Data, it should check that the loaded ID wasn't already assigned in some other Controller. ...
    (comp.lang.php)
  • Re: Inserting fields or document properties 2007
    ... You can also enable the DIP for a specific document, or documents based on a specific template, by going to Developer->Document Panel, enabling the DIP, then saving the document. ... Other options would be to use code to display them in another way, or to protect the document for forms, which would make it easier for the user to tab from control to control rather than having to click in each one in turn. ... drag-and-drop in the .dotm, in which case they would update in the .dotm, but would still be linked to the .dotm when Word created a document based on that template. ...
    (microsoft.public.word.docmanagement)
  • Re: 840807 - DLGITEMTEMPLATE
    ... Making it part of the template just sounds like taking a simple ... So, given a problem statement, how to associate data with a control, there is at least one ... >"how can i access the creation data i delivered for a control along ... >u ask "Why do you need a global function to be called?" ...
    (microsoft.public.vc.mfc)