D
dasein fiasco
I'm sure this is a design question that is commonly encountered, but I
can't find any resources which explain how to solve it. I would deeply
appreciate any advice.
Basically, when building a composite server control, I'm trying to
avoid having to build the control twice. Here's why this happens:
The routine for building the control can be called from two places:
(1) CreateChildControls, or (2) DataBind. If DataBind is called, it
sets ChildControlsCreated to false, and creates the controls itself.
If it isn't called, then CreateChildControls is automatically
invoked, and creates the controls from the ViewState. Great! This
works fine.
However, several of the child controls can change the state of the
control – essentially, the control has a table, and the table can be
rendered in different ways, so you can select different rendering
options from the control (horizontal, vertical, etc.) via
dropdownlist controls.
When one of these controls is selected, it registers an event, and
calls a routine to change some properties of the control that tell it
to render differently. However, postback events like this occur after
DataBind, and more importantly, after CreateChildControls.
If one of these events is raised, when CreateChildControls is invoked,
it doesn't know that the properties of the control are about to
change, and therefore the rendering it will perform is about to be
obsolete. What happens is that it builds the control hierarchy, then
later the event is called, which changes how the control hierarchy
should look, and so it MUST REBUILD the control hierarchy again to
respond to the changes posted by the event. Therefore, I'm building
the control hierarchy twice.
I assume I'm doing something drastically wrong in my design here, but
I can't figure out how I should handle this differently. Please, any
advice, links, pseudocode, admonishments would be greatly
appreciated.
Thanks in advance.
can't find any resources which explain how to solve it. I would deeply
appreciate any advice.
Basically, when building a composite server control, I'm trying to
avoid having to build the control twice. Here's why this happens:
The routine for building the control can be called from two places:
(1) CreateChildControls, or (2) DataBind. If DataBind is called, it
sets ChildControlsCreated to false, and creates the controls itself.
If it isn't called, then CreateChildControls is automatically
invoked, and creates the controls from the ViewState. Great! This
works fine.
However, several of the child controls can change the state of the
control – essentially, the control has a table, and the table can be
rendered in different ways, so you can select different rendering
options from the control (horizontal, vertical, etc.) via
dropdownlist controls.
When one of these controls is selected, it registers an event, and
calls a routine to change some properties of the control that tell it
to render differently. However, postback events like this occur after
DataBind, and more importantly, after CreateChildControls.
If one of these events is raised, when CreateChildControls is invoked,
it doesn't know that the properties of the control are about to
change, and therefore the rendering it will perform is about to be
obsolete. What happens is that it builds the control hierarchy, then
later the event is called, which changes how the control hierarchy
should look, and so it MUST REBUILD the control hierarchy again to
respond to the changes posted by the event. Therefore, I'm building
the control hierarchy twice.
I assume I'm doing something drastically wrong in my design here, but
I can't figure out how I should handle this differently. Please, any
advice, links, pseudocode, admonishments would be greatly
appreciated.
Thanks in advance.