My ASP.NET Page theory!

A

Amelyan

I need some help to confirm my theory!
I think I discovered something new for myself about behavior
System.Web.UI.Page.

THEORY: Every time I change control on my WebForm1 page that results in
PostBack, it is handled by a new instance of WebForm1 class, i.e. a new
instance of WebForm1 class is created every time. In general, any GET or
POST to WebForm1 will get its own new instance of WebForm1.

public class WebForm1 : System.Web.UI.Page
{
}

Is my theory correct? I wasn't able to find confirmation or contradiction
to my theory in my asp.net books.

Thank you,
-Amelyan
 
J

Joshua Flanagan

Yes, that is correct. Page objects are created to fulfill a single
request and then are destroyed after the request is complete. The only
objects that survive across requests are static objects and objects
stored in the Session, Application, or Cache objects.
 
G

Guest

In the sequence of page events, there is a page event called "Page_Unload",
which will give you appropriate info on the state of the page. This page
event will indicate that the page has been disposed. This means that each
time a page posts back to itself, all the elements in it are going to be
re-initialized.

with regards,

J.v.
 
A

Amelyan

After my request has been satisfied by the new instance of Page object, I
click the back button of Internet explorer, and I see my previous page as it
was before I issued the request. Here is the question.

Does it create a new instance of Page when I click Back button in IE, or
does it bring back my old Page object?

Thanks,
-Boris
 
L

Lucas Tam

Does it create a new instance of Page when I click Back button in IE, or
does it bring back my old Page object?

It probably brought back the cached version.
 
G

Guest

The cache is at the client machine, the page has been disposed at the server.
When you click the Back button, the page is being displayed from the client
cache. This, too, can be avoided if you make the page pull a fresh version
from the server. In which case, the Back button will never be active.

with regards,

J.v.


Amelyan said:
What happens if the Page was already garbage collected?
 
L

Lucas Tam

What happens if the Page was already garbage collected?

I meant client cache - pages on the server side are disposed of after each
run anyways. If a client side cached page is called, the server just
recreates the page and redisplays it. It's all seemless in .NET.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top