Why ViewState/ControlState Loaded After CreateChildControls?

M

Mark Olbert

Tonight's episode of me beating my head bloody against the monitor was the result of ViewState/ControlState information not being
available when CreateChildControls() gets called for a CompositeControl.

So, my question is, >>why<< isn't ViewState/ControlState available before CreateChildControls() gets called by the Framework? Is it
just me, or does it seem really counterintuitive to be creating child controls on postback without the previously-stored state
information being available? Is it that ViewState/ControlState are associated with the controls themselves, so before the controls
are created the state data can't be made available?

- Mark
 
S

Steven Cheng[MSFT]

Thanks for Eliyahu's input,

Hi Mark,

As Eliyahu has mentioned, the restore of controlstate/viewstate does occur
after the control's "CreatechildControls" be called. Actually, except the
first request(before postback), in each postback request, the control will
first reconstruct its control Tree by calling "CreateChildControls" method.
Then, it perform Init on the control hierarchy and restore
viewstate/control state from the persistent storage(the <input hidden >
element in page). And In Load event, the ViewState should has been
available there. So generally, in "CreateChildControls" method, we should
only put code that simply construct the control tree of webcontrol, and the
code logic there should not rely on those resource that are not available
at that time(such as ViewState).

I think you may have some code logic about the control structure(sub
control) depend on the viewstate. Would you provide some further
information on this? We can try looking for some other approaches to
overcome the issue.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Olbert

Me, I tend to like to have all my information and "stuff" available before building things...whether it's a woodworking project,
cooking a meal, or creating custom controls :). Just a personal quirk, I guess, and it's why I find it so counter-intuitive that
ViewState/ControlState info isn't available until after I build a constituent control.

Thanks for the reference.

- Mark
 
S

Steven Cheng[MSFT]

I agree that it's necessary to have all the information and stuff available
before building since that can avoid running into a dead way. Also,
sometimes those programming model like the ASP.NET control lifecycle look
like paradox, however, after we inspect it detailedly, we would find it
quite straighforward to use. Anyway, please feel free to post here if you
meet any other problems or have any questions on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top