View State and Control Execution Cycle

P

Pham Nguyen

I have two maybe related questions about view state and the life cycle
of controls:

1) When does the view state in a control get restored? I thought there
was a LoadViewState event that occured before the Load event when the
view state got restored. However, I have a custom control that
dynamically adds a Label control inside of its OnLoad() method. The
Label still maintains its state across requests -- if the Label is
added in the OnLoad() method of the control, shouldn't it have missed
the LoadViewState event?

2) How are the various life cycle events like Load, LoadViewState,
Init, PreRender invoked? The model I had in my mind was that these
events were raised by ASP.NET at specific points in the execution of a
page and that if a control wasn't present when an event was raised,
that it would miss out on the chance to respond to it. For instance,
the Label control above would not have its LoadViewState() method
called because it was added in the OnLoad() method of its parent,
which occurs in response to the Load event which occurs after the
LoadViewState event. This apparently is very wrong...
 
P

Pham Nguyen

That explains a lot. I haven't seen dynamic controls addressed very
well in any of the ASP.NET books I have. Thanks!

Victor Garcia Aprea said:
Hi Pham,

Let me know if this post[1] helps you understand whats going on,

[1] http://weblogs.asp.net/vga/archive/2003/08/11/23498.aspx

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup

Pham Nguyen said:
I have two maybe related questions about view state and the life cycle
of controls:

1) When does the view state in a control get restored? I thought there
was a LoadViewState event that occured before the Load event when the
view state got restored. However, I have a custom control that
dynamically adds a Label control inside of its OnLoad() method. The
Label still maintains its state across requests -- if the Label is
added in the OnLoad() method of the control, shouldn't it have missed
the LoadViewState event?

2) How are the various life cycle events like Load, LoadViewState,
Init, PreRender invoked? The model I had in my mind was that these
events were raised by ASP.NET at specific points in the execution of a
page and that if a control wasn't present when an event was raised,
that it would miss out on the chance to respond to it. For instance,
the Label control above would not have its LoadViewState() method
called because it was added in the OnLoad() method of its parent,
which occurs in response to the Load event which occurs after the
LoadViewState event. This apparently is very wrong...
 
V

Victor Garcia Aprea [MVP]

Glad it helped :)

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx

To contact me remove 'NOSPAM'. Please post all questions to the newsgroup

Pham Nguyen said:
That explains a lot. I haven't seen dynamic controls addressed very
well in any of the ASP.NET books I have. Thanks!

"Victor Garcia Aprea [MVP]" <[email protected]> wrote in message
Hi Pham,

Let me know if this post[1] helps you understand whats going on,

[1] http://weblogs.asp.net/vga/archive/2003/08/11/23498.aspx

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup

Pham Nguyen said:
I have two maybe related questions about view state and the life cycle
of controls:

1) When does the view state in a control get restored? I thought there
was a LoadViewState event that occured before the Load event when the
view state got restored. However, I have a custom control that
dynamically adds a Label control inside of its OnLoad() method. The
Label still maintains its state across requests -- if the Label is
added in the OnLoad() method of the control, shouldn't it have missed
the LoadViewState event?

2) How are the various life cycle events like Load, LoadViewState,
Init, PreRender invoked? The model I had in my mind was that these
events were raised by ASP.NET at specific points in the execution of a
page and that if a control wasn't present when an event was raised,
that it would miss out on the chance to respond to it. For instance,
the Label control above would not have its LoadViewState() method
called because it was added in the OnLoad() method of its parent,
which occurs in response to the Load event which occurs after the
LoadViewState event. This apparently is very wrong...
 

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

Top