Chirag
Chirag

Reputation: 317

What is a Page Object?

What is page object in terms of asp.net?

Please give me some information:

How can we use it in asp.net?

and

Why we are using it?

I tried to search on the internet but couldn't find a proper answer that I could easily understand.

Upvotes: 0

Views: 440

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 415810

ASP.Net WebForms, like other web platforms, is still in the business of generating responses to http requests.

When a user visits a page on your site, the web server (IIS) receives the request. Because your site has a handler set up in a certain way (by default this is done for you automatically), IIS determines that this request will be processed by the ASP.Net runtime. The ASP.Net runtime then looks up what page you requested, and uses that information to create a new page object for this request.

It's worth noting at this point that you get a new page object even if the request is just a postback to the same page the user just visited. This page object only lasts for the life of this one request, and will be discarded when the request is complete, even though the user might still be interacting with the page on their browser. A new postback will generate a new page object. A lot of people have trouble wrapping their heads around this.

Once the page object is created, the ASP.Net runtime goes through a process called the Page Lifecycle. This involves steps like loading View State, loading the Session, binding to data sources, and raising user events. Between each of the stages, an event (such as Page Load) is raised that allows you to run any custom code you want to run at this particular point in the life cycle.

At the end of the life cycle, the html result for this page is transmitted to the browser, so it can be shown to the user. At this point the page object is destroyed, and the worker thread in IIS is free to handle another request.

Upvotes: 4

Related Questions