E
Ezra Epstein
I've read the docs on "dynamically" adding a UserControl to a page. First
you have to add a declarative (ie., 100% NOT dynamic) @Reference or
@Register tag.
So.... does anyone know how to truly dynamically (just in code-behind no
change to the .aspx or .ascx file) add a UserControl.
I'm trying:
1. (re-)load the old control in the OnInit() method
2. override LoadViewState() (how ???) to keep the (just reloaded) old
control in the loop
3. override OnPreRender(): If the user action requires changing the
currently loaded Control put in the new control now. Basically, since a
post-back might have initiated this change we can't do it anytime before
post-back processing -- that leaves us with pre-render. Question here: do
we need to explicitly call SaveViewState on this just added control?
3. override SaveViewState() (how?) to save this control's and it's
Basically everything works on the first pass through (loading a new control
or changing the control: it shows up just fine) BUT it seems to not have its
view state and on post-back the control isn't correctly "wired up" so
nothing happens -- actually the control doesn't even get re-displayed on
post-back!
I've tried all this with the non-dynamic @Register tag and the control work
just fine: regular and post-back with ViewState. So the problem seems to
be:
How can one add a UserControl in a 100% dynamic way (no @Reference tag
required) and still get it to work with ViewState and post-back? (Yes,
we're adding the control to the end of it's container's list of
controls....)
Thanks,
Ezra E.
you have to add a declarative (ie., 100% NOT dynamic) @Reference or
@Register tag.
So.... does anyone know how to truly dynamically (just in code-behind no
change to the .aspx or .ascx file) add a UserControl.
I'm trying:
1. (re-)load the old control in the OnInit() method
2. override LoadViewState() (how ???) to keep the (just reloaded) old
control in the loop
3. override OnPreRender(): If the user action requires changing the
currently loaded Control put in the new control now. Basically, since a
post-back might have initiated this change we can't do it anytime before
post-back processing -- that leaves us with pre-render. Question here: do
we need to explicitly call SaveViewState on this just added control?
3. override SaveViewState() (how?) to save this control's and it's
Basically everything works on the first pass through (loading a new control
or changing the control: it shows up just fine) BUT it seems to not have its
view state and on post-back the control isn't correctly "wired up" so
nothing happens -- actually the control doesn't even get re-displayed on
post-back!
I've tried all this with the non-dynamic @Register tag and the control work
just fine: regular and post-back with ViewState. So the problem seems to
be:
How can one add a UserControl in a 100% dynamic way (no @Reference tag
required) and still get it to work with ViewState and post-back? (Yes,
we're adding the control to the end of it's container's list of
controls....)
Thanks,
Ezra E.