468,101 Members | 1,325 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,101 developers. It's quick & easy.

Question on Page lifecycle...

Hello All,

I have a question which is pertinent to Page's lifecycle.

I declared a protected static object (global variable) whose value is set
only once when the page is loaded. Will that object's value be accessible
during consequent postbacks or is it set to null after HTML is rendered
initially?

I am assuming that it would be set to null because all the objects are
destroyed since Page object is killed after HTML has been rendered. In this
case ViewState does not make sense because it is an object and not a server
control.....correct?

Am I right or can anyone please explain me the concept?

Thanks a bunch!!!
Jan 10 '06 #1
2 1492
Diffident,
It depends where your object is declared. if you declare a static object in
the Global class (global.asax) this remains alive. Since a page class'
lifecycle is limited, meaning as soon as the generated response stream is
sent out to the browser it is extinguished, it doesn't make sense to do this
inside a page class.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Diffident" wrote:
Hello All,

I have a question which is pertinent to Page's lifecycle.

I declared a protected static object (global variable) whose value is set
only once when the page is loaded. Will that object's value be accessible
during consequent postbacks or is it set to null after HTML is rendered
initially?

I am assuming that it would be set to null because all the objects are
destroyed since Page object is killed after HTML has been rendered. In this
case ViewState does not make sense because it is an object and not a server
control.....correct?

Am I right or can anyone please explain me the concept?

Thanks a bunch!!!

Jan 11 '06 #2
Session variable live in the scope of application. This means that not only
consequent postbacks within the same session will access the same value, but
also other sessions of the same applications will do.

Eliyahu

"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:73**********************************@microsof t.com...
Hello All,

I have a question which is pertinent to Page's lifecycle.

I declared a protected static object (global variable) whose value is set
only once when the page is loaded. Will that object's value be accessible
during consequent postbacks or is it set to null after HTML is rendered
initially?

I am assuming that it would be set to null because all the objects are
destroyed since Page object is killed after HTML has been rendered. In
this
case ViewState does not make sense because it is an object and not a
server
control.....correct?

Am I right or can anyone please explain me the concept?

Thanks a bunch!!!

Jan 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Lau | last post: by
reply views Thread by Bryce Budd | last post: by
4 posts views Thread by Jeremy Holt | last post: by
4 posts views Thread by Diffident | last post: by
19 posts views Thread by Mark Rae | last post: by
2 posts views Thread by Gary W. Smith | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.