I believe that dynamically added controls must be created in Page_Init in
order to have their properties set automatically from the viewstate. I'd
image the IsPostBack property works the same way.
One option is to add the user control at design time then simply show/hide
it at runtime. Another option is to always add the user control in Page_Init
then remove it (in, say, PreRender) if it is not ultimately needed. Finally,
you could keep your "IsInitial" viewstate property but check it in Page_Init
and create the user control if it is true (and maybe rename it to
"LoadUserControl").
> Hi,
>
[quoted text clipped - 27 lines]
> Kind regards
> DC
DC - 03 Dec 2007 08:26 GMT
On 30 Nov., 16:23, "Scott Roberts" <srobe...@no.spam.here-webworks-
software.com> wrote:
> I believe that dynamically added controls must be created in Page_Init in
> order to have their properties set automatically from the viewstate. I'd
[quoted text clipped - 40 lines]
>
> - Zitierten Text anzeigen -
Thank you, Scott!
I tried loading the control in OnInit but the only difference I got is
that I cannot do the loading depending on some other controls that
depend from viewstate (since they will not have their viewstate
processed yet). The dynamically loaded control does still always have
"IsPostBack == true".
I am quiet convinced that the design of my application is flawed. What
I want to design is a MultiView with rather large fat controls in
every view. I wanted to avoid that all the applications in all the
views execute Page_Load on all PostBacks - although they are actually
hidden.
So I thought it was smart to dynamically load the control only when
the actual View of the control was the active view. Of course, the
control that I would then dynamically load into the View must have
"IsPostBack == false" on the initial load on "IsPostBack == true" on
subsequent loads of the same View.
So what I want is like a page in a page, kind of like I was loading
the control in the view into an Iframe and have it live its private
life. Once another View is activated, the dynamically loaded control
is allowed to loose its state.
But I think that's not a good design in ASP.Net since the architecture
relies on one state for the whole page (it is a similar problem like
the "one serverside form per page only" limitation). So I am better of
to plant all the controls into their views at designtime and get the
advantage of retaining their state (if that is desired). I will do
that now and measure the actual performance hit.
Regards
DC