473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why ViewState/ControlState Loaded After CreateChildControls?

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
Jan 31 '07 #1
5 7227
Are you dynamically adding the composite control to the page?

--
~~~~~~~~~~~
Ben Rush
http://www.ben-rush.net/compilererrors
"Mark Olbert" <Ch*********@newsgroups.nospamwrote in message
news:vn********************************@4ax.com...
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

Jan 31 '07 #2
Mark,

I think it makes perfect sense. ViewState contains values that are to be
assigned to control properties. Obviously, the controls are supposed to be
created before this. Read more about the page life cycle:

http://msdn2.microsoft.com/en-us/lib...72(VS.80).aspx

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mark Olbert" <Ch*********@newsgroups.nospamwrote in message
news:vn********************************@4ax.com...
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

Jan 31 '07 #3
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/subscripti...ult.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/subscripti...t/default.aspx.

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

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

Jan 31 '07 #4
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

On Wed, 31 Jan 2007 10:18:42 +0200, "Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote:
>Mark,

I think it makes perfect sense. ViewState contains values that are to be
assigned to control properties. Obviously, the controls are supposed to be
created before this. Read more about the page life cycle:

http://msdn2.microsoft.com/en-us/lib...72(VS.80).aspx
Jan 31 '07 #5
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.

Feb 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
1
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
6
by: Peter Zolja | last post by:
Hi, I'm building a webcontrol that contains a dynamic list of other controls. My problem is that when I add or remove an item the synchronization between the ViewState and the Controls...
5
by: Mark Olbert | last post by:
I have a composite control (under ASPNET2; derived from CompositeControl) which contains a label. The contents of the label are set when the control is created to a user-supplied value. What's...
4
by: Rolf Welskes | last post by:
Hello, the problem seems simple I have an own webcontrol one property is public bool IsEdit { get
12
by: Nick C | last post by:
Hi How can i reduce the viewstate for my asp.net application. It is getting very large now. What is a good solution? thanks N
0
by: michavo2000 | last post by:
Ok, first of all, forgiveness for my English. I understand the sequence of events within a control. However, I have a problem when dynamically generates controles. The Control, loads a...
1
by: bill | last post by:
Hi folks, we have a scenario whereby we're not too worried about cpu cycles on the server, and much more worried about users with slow up-stream connections to the server. Our goal is to... 1)...
2
by: Edward | last post by:
I am reading MSDN doc about Control's ViewState and ControlState. I got myself quite puzzled. I see that the Control class has four virtual functions: LoadControlState LoadViewState...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.